Class: LCBO::StorePage
Constant Summary
collapse
- FEATURE_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 => 'corner',
: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
#feature_cells ⇒ Object
118
119
120
121
122
|
# File 'lib/lcbo/pages/store_page.rb', line 118
def feature_cells
@feature_cells ||= begin
doc.css('input[type="checkbox"]').map { |el| el.parent.inner_html }
end
end
|
#features ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'lib/lcbo/pages/store_page.rb', line 124
def features
@details ||= begin
Hash[FEATURE_FIELDS.map { |field, term|
cell = feature_cells.detect { |cell| cell.include?(term) }
value = cell.include?('checked')
[field, value]
}]
end
end
|
#get_info_node_offset(index) ⇒ Object
112
113
114
115
116
|
# File 'lib/lcbo/pages/store_page.rb', line 112
def get_info_node_offset(index)
pos = (info_nodes_count == 9 ? index : index + 1)
pos += (info_nodes_count == 9 ? 1 : -1) unless has_fax?
pos
end
|
#has_fax? ⇒ Boolean
134
135
136
|
# File 'lib/lcbo/pages/store_page.rb', line 134
def has_fax?
info_nodes.to_s.include?('Fax:')
end
|
#info_nodes ⇒ Object
160
161
162
|
# File 'lib/lcbo/pages/store_page.rb', line 160
def info_nodes
doc.css('#storeDetails td.main_font')
end
|
#info_nodes_count ⇒ Object
156
157
158
|
# File 'lib/lcbo/pages/store_page.rb', line 156
def info_nodes_count
info_nodes.size
end
|
#open_close_times ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/lcbo/pages/store_page.rb', line 138
def open_close_times
@open_close_times ||= begin
days = Date::DAYNAMES.map { |d| d.downcase }
Hash[days.each_with_index.map { |day, idx|
text = doc.css("#row#{idx}Time.hours")[0].content
next [day, [nil, nil]] if text.include?('Closed')
times = text.split('-')
open, close = *times.map { |time|
hour, min = *time.sub(/AM|PM/, '').strip.split(':').map { |t| t.to_i }
hour += 12 if time.include?('PM') && (hour >= 1 && hour <= 11)
hour = 0 if time.include?('AM') && hour == 12
(hour * 60) + min
}
[day, (open == close ? [nil, nil] : [open, close])]
}]
end
end
|
#verify_store_returned ⇒ Object
164
165
166
167
|
# File 'lib/lcbo/pages/store_page.rb', line 164
def verify_store_returned
return if !@html.include?('No stores were located using your criteria.')
raise CrawlKit::NotFoundError, "store #{id} does not exist"
end
|
#verify_telephone_number ⇒ Object
169
170
171
172
173
|
# File 'lib/lcbo/pages/store_page.rb', line 169
def verify_telephone_number
return if telephone
raise CrawlKit::MalformedError,
"unable to locate telephone number for store #{id}"
end
|