lcbo 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,21 @@
1
+ Version 0.9.6
2
+
3
+ * Removed instances of `Enumerable#reduce` in favour of `Hash[]` for
4
+ constructing hashes.
5
+ * Added `price_per_liter_in_cents` and `price_per_liter_of_alcohol_in_cents`
6
+ to ProductPage.
7
+
8
+ Version 0.9.5
9
+
10
+ * Fixed an encoding bug.
11
+
12
+ Version 0.9.4
13
+
14
+ * Set default value for `ProductListsCrawler`'s `:page` param to zero.
15
+
1
16
  Version 0.9.3
2
17
 
3
- * 4x speed boost to InventoryPage.parse courtesy of Justin Giancola.
18
+ * 4x speed boost to `InventoryPage.parse` courtesy of Justin Giancola.
4
19
 
5
20
  Version 0.9.2
6
21
 
@@ -125,9 +125,7 @@ module LCBO
125
125
  end
126
126
 
127
127
  def as_hash
128
- @as_hash ||= begin
129
- fields.reduce({}) { |hsh, field| hsh.merge(field => send(field)) }
130
- end
128
+ @as_hash ||= Hash[fields.map { |field| [field, send(field)] }]
131
129
  end
132
130
 
133
131
  protected
@@ -2,11 +2,11 @@ module LCBO
2
2
  module HashExt
3
3
 
4
4
  def self.symbolize_keys(input)
5
- input.reduce({}) { |hsh, (key, value)| hsh.merge(key.to_sym => value) }
5
+ Hash[input.map { |key, value| [key.to_sym, value] }]
6
6
  end
7
7
 
8
8
  def self.stringify_keys(input)
9
- input.reduce({}) { |hsh, (key, value)| hsh.merge(key.to_s => value) }
9
+ Hash[input.map { |key, value| [key.to_sym, value] }]
10
10
  end
11
11
 
12
12
  end
@@ -121,23 +121,40 @@ module LCBO
121
121
  end
122
122
 
123
123
  emits :alcohol_content do
124
- match = find_info_line(/ Alcohol\/Vol.\Z/)
125
- if match
124
+ if (match = find_info_line(/ Alcohol\/Vol.\Z/))
126
125
  ac = match.gsub(/%| Alcohol\/Vol./, '').to_f
127
- ac.zero? ? nil : (ac * 100).to_i
126
+ (ac * 100).to_i
127
+ else
128
+ 0
129
+ end
130
+ end
131
+
132
+ emits :price_per_liter_of_alcohol_in_cents do
133
+ if alcohol_content > 0 && volume_in_milliliters > 0
134
+ alc_frac = alcohol_content.to_f / 1000.0
135
+ alc_vol = (volume_in_milliliters.to_f / 1000.0) * alc_frac
136
+ (price_in_cents.to_f / alc_vol).to_i
137
+ else
138
+ 0
139
+ end
140
+ end
141
+
142
+ emits :price_per_liter_in_cents do
143
+ if volume_in_milliliters > 0
144
+ (price_in_cents.to_f / (volume_in_milliliters.to_f / 1000.0)).to_i
145
+ else
146
+ 0
128
147
  end
129
148
  end
130
149
 
131
150
  emits :sugar_content do
132
- match = match = find_info_line(/\ASugar Content : /)
133
- if match
151
+ if (match = find_info_line(/\ASugar Content : /))
134
152
  match.gsub('Sugar Content : ', '')
135
153
  end
136
154
  end
137
155
 
138
156
  emits :producer_name do
139
- match = find_info_line(/\ABy: /)
140
- if match
157
+ if (match = find_info_line(/\ABy: /))
141
158
  CrawlKit::TitleCaseHelper[
142
159
  match.gsub(/By: |Tasting Note|Serving Suggestion|NOTE:/, '')
143
160
  ]
@@ -252,9 +269,7 @@ module LCBO
252
269
  end
253
270
 
254
271
  def info_cell_line_after(item)
255
- i = info_cell_lines.index(item)
256
- return unless i
257
- info_cell_lines[i + 1]
272
+ (i = info_cell_lines.index(item)) ? info_cell_lines[i + 1] : nil
258
273
  end
259
274
 
260
275
  def info_cell_html
@@ -1,3 +1,3 @@
1
1
  module LCBO
2
- VERSION = '0.9.5'
2
+ VERSION = '0.9.6'
3
3
  end
@@ -14,6 +14,8 @@
14
14
  :bonus_reward_miles: 0
15
15
  :bonus_reward_miles_ends_on:
16
16
  :alcohol_content: 1270
17
+ :price_per_liter_of_alcohol_in_cents: 1254
18
+ :price_per_liter_in_cents: 1593
17
19
  :sugar_content: "1"
18
20
  :package: 750 mL bottle
19
21
  :package_unit_type: bottle
@@ -51,6 +53,8 @@
51
53
  :bonus_reward_miles: 0
52
54
  :bonus_reward_miles_ends_on:
53
55
  :alcohol_content: 500
56
+ :price_per_liter_of_alcohol_in_cents: 1262
57
+ :price_per_liter_in_cents: 631
54
58
  :sugar_content: "7"
55
59
  :package: 6x330 mL bottle
56
60
  :package_unit_type: bottle
@@ -88,6 +92,8 @@
88
92
  :bonus_reward_miles: 30
89
93
  :bonus_reward_miles_ends_on: "2010-08-14"
90
94
  :alcohol_content: 1250
95
+ :price_per_liter_of_alcohol_in_cents: 23461
96
+ :price_per_liter_in_cents: 29326
91
97
  :sugar_content: XD
92
98
  :package: 750 mL bottle
93
99
  :package_unit_type: bottle
@@ -125,6 +131,8 @@
125
131
  :bonus_reward_miles: 0
126
132
  :bonus_reward_miles_ends_on:
127
133
  :alcohol_content: 350
134
+ :price_per_liter_of_alcohol_in_cents: 2164
135
+ :price_per_liter_in_cents: 757
128
136
  :sugar_content: "8"
129
137
  :package: 330 mL bottle
130
138
  :package_unit_type: bottle
@@ -162,6 +170,8 @@
162
170
  :bonus_reward_miles: 0
163
171
  :bonus_reward_miles_ends_on:
164
172
  :alcohol_content: 1320
173
+ :price_per_liter_of_alcohol_in_cents: 1611
174
+ :price_per_liter_in_cents: 2126
165
175
  :sugar_content: "XD"
166
176
  :package: 750 mL bottle
167
177
  :package_unit_type: bottle
@@ -199,6 +209,8 @@
199
209
  :bonus_reward_miles: 0
200
210
  :bonus_reward_miles_ends_on:
201
211
  :alcohol_content: 4000
212
+ :price_per_liter_of_alcohol_in_cents: 792
213
+ :price_per_liter_in_cents: 3168
202
214
  :sugar_content:
203
215
  :package: 1750 mL bottle
204
216
  :package_unit_type: bottle
@@ -236,6 +248,8 @@
236
248
  :bonus_reward_miles: 0
237
249
  :bonus_reward_miles_ends_on:
238
250
  :alcohol_content: 1220
251
+ :price_per_liter_of_alcohol_in_cents: 1196
252
+ :price_per_liter_in_cents: 1460
239
253
  :sugar_content:
240
254
  :package: 750 mL bottle
241
255
  :package_unit_type: bottle
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 5
9
- version: 0.9.5
8
+ - 6
9
+ version: 0.9.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Carsten Nielsen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-30 00:00:00 -05:00
17
+ date: 2010-12-01 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency