-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.rb
More file actions
76 lines (58 loc) · 1.33 KB
/
helpers.rb
File metadata and controls
76 lines (58 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
helpers do
def hospital_class(hospital)
@count ||= 0
classes = ''
if(@count == 0 || @count % 3 == 0)
classes += ' clear'
end
if(@count % 2 == 0)
classes += ' even'
else
classes += ' odd'
end
classes += " col_#{@count % 3}"
@count += 1
classes
end
def comment_class(comment)
@comment_count ||= 0
classes = ''
if(@comment_count % 2 == 0)
classes += ' even'
else
classes += ' odd'
end
@comment_count += 1
classes
end
def problem_class(problem)
@problem_count ||= 0
classes = ''
if(@problem_count % 2 == 0)
classes += ' even'
else
classes += ' odd'
end
@problem_count += 1
classes
end
def get_services(q)
hospitals = nil
cache_file = "./cache/find_#{q.gsub(/\W/, '_').downcase}.yaml"
if File.exists?(cache_file)
hospitals = YAML::load(File.read(cache_file))
puts "# Results for '#{q}' retrieved from cache: #{cache_file}"
else
puts "# Fetching results for '#{q}'"
hospitals = NHSHospitals.new(q)
File.open(cache_file, 'w') do |out|
YAML::dump(hospitals, out)
end
end
hospitals
end
def get_service(code1, code2)
cache_file = "./cache/service_#{code1}_#{code2}"
YAML::load(File.open(cache_file).read())
end
end