rsr_group 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0f481ef1a7f01597b9a2ebc8cbf4746753ded79
4
- data.tar.gz: 338d2906e092f2dde9eb4c70e82e6a4df09d0784
3
+ metadata.gz: fa4198a0176561bf852aee7ca7c1df677009644b
4
+ data.tar.gz: 84c44fffbc967de623172cc301bb347ae252b297
5
5
  SHA512:
6
- metadata.gz: 474b7d64cf637aca038f0819ac04937333ec966af319ca6b0127324529387d09ecf363e0aaf504a7f5d726224aedd3bd1c121a77445560e78d1020753b5b52bb
7
- data.tar.gz: 1096c09838ff43a1313a6767b80f86a9a0db9b787a8ee86e1405339435d4d68ce86d3ef8442356773a2e18b863f07bbf66932088d2240883b402ceece8465cd0
6
+ metadata.gz: 2a2a11c324f55c6638aaad729fd83365d4cb624ff67636c7d949efcde5b91078cce856addca1345fb54783bc6dc79254c32c7ed1d276b0ecec029052a1d9acb3
7
+ data.tar.gz: 689d5eea5422d3fe95b71c71c21ece566d596cd9896fb961f3e354c11970b38f92964a5447fb35995979cd90bf6fc40fdec889fcd87fab330fe5c8f2909e8c1a
data/lib/rsr_group.rb CHANGED
@@ -3,6 +3,7 @@ require 'rsr_group/version'
3
3
  require 'csv'
4
4
  require 'date'
5
5
  require 'net/ftp'
6
+ require 'smarter_csv'
6
7
 
7
8
  require 'rsr_group/base'
8
9
  require 'rsr_group/constants'
@@ -18,6 +18,13 @@ module RsrGroup
18
18
  new(options).all
19
19
  end
20
20
 
21
+ def self.process_as_chunks(size = 15, options = {})
22
+ requires!(options, :username, :password)
23
+ new(options).process_as_chunks(size) do |chunk|
24
+ yield(chunk)
25
+ end
26
+ end
27
+
21
28
  def self.map_prices(options = {})
22
29
  requires!(options, :username, :password)
23
30
  new(options).map_prices
@@ -129,6 +136,45 @@ module RsrGroup
129
136
  items
130
137
  end
131
138
 
139
+ def process_as_chunks(size)
140
+ connect(@options) do |ftp|
141
+ chunk = []
142
+ item_count = 1
143
+ temp_csv_file = Tempfile.new
144
+
145
+ if ftp.nlst.include?(KEYDEALER_DIR)
146
+ ftp.chdir(KEYDEALER_DIR)
147
+ ftp.getbinaryfile(KEYDEALER_FILENAME, temp_csv_file.path)
148
+ else
149
+ ftp.chdir(INVENTORY_DIR)
150
+ ftp.getbinaryfile(INVENTORY_FILENAME, temp_csv_file.path)
151
+ end
152
+
153
+ line_count = File.readlines(temp_csv_file).size
154
+
155
+ CSV.readlines(temp_csv_file, col_sep: ';', quote_char: "\x00").to_enum.with_index(1).each do |row, current_line|
156
+ chunk << process_row(row)
157
+
158
+ # Return chunk if we have reached the end of the file
159
+ if line_count == current_line
160
+ yield(chunk)
161
+ end
162
+
163
+ # Return if chuck is full
164
+ if item_count == size
165
+ yield(chunk)
166
+
167
+ chunk = []
168
+ item_count = 1
169
+ else
170
+ item_count += 1
171
+ end
172
+ end
173
+
174
+ temp_csv_file.unlink
175
+ end
176
+ end
177
+
132
178
  def map_prices
133
179
  rows = []
134
180
 
@@ -185,5 +231,87 @@ module RsrGroup
185
231
  data.strip
186
232
  end
187
233
 
234
+ def process_row(row)
235
+ {
236
+ stock_number: sanitize(row[0]),
237
+ upc: sanitize(row[1]),
238
+ description: sanitize(row[2]),
239
+ department: row[3].nil? ? row[3] : RsrGroup::Department.new(row[3]),
240
+ manufacturer_id: sanitize(row[4]),
241
+ retail_price: sanitize(row[5]),
242
+ regular_price: sanitize(row[6]),
243
+ weight: sanitize(row[7]),
244
+ quantity: (Integer(sanitize(row[8])) rescue 0),
245
+ model: sanitize(row[9]),
246
+ manufacturer_name: sanitize(row[10]),
247
+ manufacturer_part_number: sanitize(row[11]),
248
+ allocated_closeout_deleted: sanitize(row[12]),
249
+ description_full: sanitize(row[13]),
250
+ image_name: sanitize(row[14]),
251
+ restricted_states: {
252
+ AK: row[15] == 'Y',
253
+ AL: row[16] == 'Y',
254
+ AR: row[17] == 'Y',
255
+ AZ: row[18] == 'Y',
256
+ CA: row[19] == 'Y',
257
+ CO: row[20] == 'Y',
258
+ CT: row[21] == 'Y',
259
+ DC: row[22] == 'Y',
260
+ DE: row[23] == 'Y',
261
+ FL: row[24] == 'Y',
262
+ GA: row[25] == 'Y',
263
+ HI: row[26] == 'Y',
264
+ IA: row[27] == 'Y',
265
+ ID: row[28] == 'Y',
266
+ IL: row[29] == 'Y',
267
+ IN: row[30] == 'Y',
268
+ KS: row[31] == 'Y',
269
+ KY: row[32] == 'Y',
270
+ LA: row[33] == 'Y',
271
+ MA: row[36] == 'Y',
272
+ MD: row[37] == 'Y',
273
+ ME: row[38] == 'Y',
274
+ MI: row[39] == 'Y',
275
+ MN: row[40] == 'Y',
276
+ MO: row[41] == 'Y',
277
+ MS: row[42] == 'Y',
278
+ MT: row[43] == 'Y',
279
+ NC: row[44] == 'Y',
280
+ ND: row[45] == 'Y',
281
+ NE: row[46] == 'Y',
282
+ NH: row[47] == 'Y',
283
+ NJ: row[48] == 'Y',
284
+ NM: row[49] == 'Y',
285
+ NV: row[50] == 'Y',
286
+ NY: row[51] == 'Y',
287
+ OH: row[52] == 'Y',
288
+ OK: row[53] == 'Y',
289
+ OR: row[54] == 'Y',
290
+ PA: row[55] == 'Y',
291
+ RI: row[56] == 'Y',
292
+ SC: row[57] == 'Y',
293
+ SD: row[58] == 'Y',
294
+ TN: row[59] == 'Y',
295
+ TX: row[60] == 'Y',
296
+ UT: row[61] == 'Y',
297
+ VA: row[62] == 'Y',
298
+ VT: row[63] == 'Y',
299
+ WA: row[64] == 'Y',
300
+ WI: row[65] == 'Y',
301
+ WV: row[66] == 'Y',
302
+ WY: row[67] == 'Y',
303
+ },
304
+ ground_shipping_only: row[68] == 'Y',
305
+ adult_signature_required: row[69] == 'Y',
306
+ blocked_from_drop_ship: row[70] == 'Y',
307
+ date_entered: row[71].nil? ? row[71] : Date.strptime(row[71], '%Y%m%d'),
308
+ retail_map: sanitize(row[72]),
309
+ image_disclaimer: row[73] == 'Y',
310
+ shipping_length: sanitize(row[74]),
311
+ shipping_width: sanitize(row[75]),
312
+ shipping_height: sanitize(row[76]),
313
+ }
314
+ end
315
+
188
316
  end
189
317
  end
@@ -1,3 +1,3 @@
1
1
  module RsrGroup
2
- VERSION = '1.6.1'
2
+ VERSION = '1.6.2'
3
3
  end
data/rsr_group.gemspec CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
+ spec.add_runtime_dependency "smarter_csv", "~> 1.1.4"
28
+
27
29
  spec.add_development_dependency "bundler", "~> 1.12"
28
30
  spec.add_development_dependency "rake", "~> 10.0"
29
31
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsr_group
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Campbell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-07 00:00:00.000000000 Z
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: smarter_csv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.4
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
133
  version: '0'
120
134
  requirements: []
121
135
  rubyforge_project:
122
- rubygems_version: 2.6.7
136
+ rubygems_version: 2.5.1
123
137
  signing_key:
124
138
  specification_version: 4
125
139
  summary: RSR Group Ruby library