Class: LCBO::StorePage
Constant Summary
collapse
- DAY_NAMES =
%w[
monday
tuesday
wednesday
thursday
friday
saturday
sunday ]
- DETAIL_FIELDS =
{
:has_wheelchair_accessability => 'wheelchair',
:has_bilingual_services => 'bilingual',
:has_product_consultant => 'consultant',
:has_tasting_bar => 'tasting',
:has_beer_cold_room => 'cold',
:has_special_occasion_permits => 'permits',
:has_vintages_corner => 'vintages',
:has_parking => 'parking',
:has_transit_access => 'transit' }
Instance Method Summary
collapse
#[], #as_hash, #fields, #http_method, included, #initialize, #is_parsed?, #parse, #process, #request, #request_prototype
Instance Method Details
#container_table ⇒ Object
153
154
155
|
# File 'lib/lcbo/pages/store_page.rb', line 153
def container_table
@doc.css('table.border[width="478"]')
end
|
#detail_rows ⇒ Object
106
107
108
109
110
|
# File 'lib/lcbo/pages/store_page.rb', line 106
def detail_rows
@detail_rows ||= begin
doc.css('input[type="checkbox"]').map { |e| e.parent.parent.inner_html }
end
end
|
#details ⇒ Object
112
113
114
115
116
117
118
119
120
|
# File 'lib/lcbo/pages/store_page.rb', line 112
def details
@details ||= begin
DETAIL_FIELDS.reduce({}) do |hsh, (field, term)|
row = detail_rows.detect { |row| row.include?(term) }
value = row.include?('checked')
hsh.merge(field => value)
end
end
end
|
#expected_node_count ⇒ Object
171
172
173
|
# File 'lib/lcbo/pages/store_page.rb', line 171
def expected_node_count
has_fax? ? 8 : 7
end
|
#has_fax? ⇒ Boolean
130
131
132
|
# File 'lib/lcbo/pages/store_page.rb', line 130
def has_fax?
info_nodes.to_s.include?('Fax: ')
end
|
#hours_table ⇒ Object
157
158
159
|
# File 'lib/lcbo/pages/store_page.rb', line 157
def hours_table
container_table.css('table[width="100%"]')
end
|
#info_nodes ⇒ Object
161
162
163
|
# File 'lib/lcbo/pages/store_page.rb', line 161
def info_nodes
container_table.css('td[width="48%"]')
end
|
#location ⇒ Object
126
127
128
|
# File 'lib/lcbo/pages/store_page.rb', line 126
def location
CGI.parse(URI.parse(map_anchor_href).query)
end
|
#map_anchor_href ⇒ Object
122
123
124
|
# File 'lib/lcbo/pages/store_page.rb', line 122
def map_anchor_href
info_nodes[has_fax? ? 6 : 5].css('a').first.attributes['href'].to_s
end
|
#open_close_times ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/lcbo/pages/store_page.rb', line 138
def open_close_times
@open_close_times ||= begin
time_cells.inject({}) do |hsh, td|
text = td.text.gsub(/\s+/, ' ')
day = text.match(/[MTWTFS]{1}[a-z]+/).to_s.downcase
times = text.scan(/[0-9]{1,2}:[0-9]{2}/)
open, close = *times.map { |time|
hour, min = *time.split(':').map { |t| t.to_i }
(hour * 60) + min
}
hsh.merge(day => (open == close ? [nil, nil] : [open, close]))
end
end
end
|
#time_cells ⇒ Object
165
166
167
168
169
|
# File 'lib/lcbo/pages/store_page.rb', line 165
def time_cells
hours_table.
css('td[width="50%"] tr').
select { |td| td.to_s =~ /[MTWTFS]{1}[onuesdhriat]{2,5}day/ }
end
|
#time_open_close(day) ⇒ Object
134
135
136
|
# File 'lib/lcbo/pages/store_page.rb', line 134
def time_open_close(day)
open_close_times[day.to_s.downcase]
end
|
#verify_node_count ⇒ Object
186
187
188
189
190
191
|
# File 'lib/lcbo/pages/store_page.rb', line 186
def verify_node_count
return if expected_node_count == info_nodes.size
raise MalformedDocumentError,
"Expected #{expected_node_count} nodes for store #{store_no} but found " \
"#{info_nodes.size} instead."
end
|
#verify_store_returned ⇒ Object
175
176
177
178
|
# File 'lib/lcbo/pages/store_page.rb', line 175
def verify_store_returned
return if !@html.include?('No stores were located using your criteria.')
raise MissingResourceError, "store #{store_no} does not exist"
end
|
#verify_telephone_number ⇒ Object
180
181
182
183
184
|
# File 'lib/lcbo/pages/store_page.rb', line 180
def verify_telephone_number
return if telephone
raise MalformedDocumentError,
"unable to locate telephone number for store #{store_no}"
end
|