rsr_group 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe5517c688477cb0af67c4b4710f8764ece96feb
4
- data.tar.gz: b5fa94f53bf559d2854889233621a0899a48844a
3
+ metadata.gz: ade549f57a9f051ee13fc17901098c134fdc9e91
4
+ data.tar.gz: 20a5d061bb389fe4ff6eea46e953d62530d8975a
5
5
  SHA512:
6
- metadata.gz: 93c82484ea8805744e148640da0bf9c5e27f884dcfa7670688ef52f4a2f2419b2e91e9fc7b293c75606575e97656e60ec160d540f85844f7a21e861111bfa61c
7
- data.tar.gz: c40e6c4b4652d40340b163d5995da8df7c02bef0051f5aabbf9097e97c88a078ffb170552420b1d10249ac3188d143e146c08b46f5044f121132064a9aaa36b5
6
+ metadata.gz: f0e492ba80329ac4cac1ad22dbf77935d69711a0af09f5b27d878036bb5b8253e8253281858d3c1e865546292f147f9897586ea1ebbfcf88a13250efa7327024
7
+ data.tar.gz: 1a504cd1c3c4aaccffc0efba67e407e8d4113d7cc0d0c808bccbe0978dbbd31350ee1327e1a5c24f3c53e38ba59365a9e392447b2fd9fc60d5dbba55c44f494e
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 'tempfile'
6
7
  require 'smarter_csv'
7
8
 
8
9
  require 'rsr_group/base'
@@ -1,10 +1,28 @@
1
1
  module RsrGroup
2
2
  class Inventory < Base
3
3
 
4
- KEYDEALER_DIR = 'keydealer'.freeze
5
- INVENTORY_DIR = 'ftpdownloads'.freeze
6
- QTY_FILENAME = 'IM-QTY-CSV.csv'.freeze
7
- MAP_FILENAME = 'retail-map.csv'.freeze
4
+ KEYDEALER_DIR = 'keydealer'.freeze
5
+ INVENTORY_DIR = 'ftpdownloads'.freeze
6
+ QTY_FILENAME = 'IM-QTY-CSV.csv'.freeze
7
+ MAP_FILENAME = 'retail-map.csv'.freeze
8
+ INVENTORY_FILENAME = 'rsrinventory-new.txt'.freeze
9
+ KEYDEALER_FILENAME = 'rsrinventory-keydlr-new.txt'.freeze
10
+
11
+ DEFAULT_SMART_OPTS = {
12
+ chunk_size: 100,
13
+ convert_values_to_numeric: false,
14
+ col_sep: ";",
15
+ quote_char: "|",
16
+ headers_in_file: false,
17
+ user_provided_headers: [
18
+ :stock_number, :upc, :short_description, :department_number, :manufacturer_id, :retail_price,
19
+ :price, :weight, :quantity, :model, :manufacturer, :mfg_number, :allocated_closeout_deleted, :long_description,
20
+ :image_name, 51.times.map { |i| "state_#{i}".to_sym }, :ships_ground_only, :signature_required, :blocked_from_drop_ship,
21
+ :date_entered, :map_price, :image_disclaimer, :length, :width, :height, :null
22
+ ].flatten,
23
+ remove_unmapped_keys: true,
24
+ verbose: true
25
+ }
8
26
 
9
27
  def initialize(options = {})
10
28
  requires!(options, :username, :password)
@@ -12,47 +30,31 @@ module RsrGroup
12
30
  @options = options
13
31
  end
14
32
 
15
- def self.all(chunk_size = 15, options = {}, &block)
33
+ def self.all(chunk_size, options = {}, &block)
16
34
  requires!(options, :username, :password)
17
35
  new(options).all(chunk_size, &block)
18
36
  end
19
37
 
20
38
  def all(chunk_size, &block)
21
39
  connect(@options) do |ftp|
22
- chunker = RsrGroup::Chunker.new(chunk_size)
23
- csv_tempfile = Tempfile.new
40
+ tempfile = Tempfile.new
24
41
 
25
42
  # Is this a key dealer?
26
43
  if ftp.nlst.include?(KEYDEALER_DIR)
27
44
  ftp.chdir(KEYDEALER_DIR)
45
+ # Pull from the FTP and save as a temp file
46
+ ftp.getbinaryfile(KEYDEALER_FILENAME, tempfile.path)
28
47
  else
29
48
  ftp.chdir(INVENTORY_DIR)
49
+ # Pull from the FTP and save as a temp file
50
+ ftp.getbinaryfile(INVENTORY_FILENAME, tempfile.path)
30
51
  end
31
52
 
32
- # Pull from the FTP and save as a temp file
33
- ftp.getbinaryfile(QTY_FILENAME, csv_tempfile.path)
34
-
35
- # total_count is hte number of lines in the file
36
- chunker.total_count = File.readlines(csv_tempfile).size
37
-
38
- CSV.readlines(csv_tempfile).each do |row|
39
- if chunker.is_full?
40
- yield(chunker.chunk)
41
-
42
- chunker.reset
43
- elsif chunker.is_complete?
44
- yield(chunker.chunk)
45
-
46
- break
47
- else
48
- chunker.add({
49
- item_identifier: row[0].rstrip,
50
- quantity: row[1].to_i
51
- })
52
- end
53
+ SmarterCSV.process(tempfile, DEFAULT_SMART_OPTS.merge(chunk_size: chunk_size)) do |chunk|
54
+ yield(chunk)
53
55
  end
54
56
 
55
- csv_tempfile.unlink
57
+ tempfile.unlink
56
58
  ftp.close
57
59
  end
58
60
  end
@@ -1,3 +1,3 @@
1
1
  module RsrGroup
2
- VERSION = '2.0.4'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
data/rsr_group.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'rsr_group/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.required_ruby_version = '~> 2.0'
7
+ spec.required_ruby_version = '>= 2.0'
8
8
 
9
9
  spec.name = "rsr_group"
10
10
  spec.version = RsrGroup::VERSION
@@ -24,7 +24,7 @@ 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"
27
+ spec.add_runtime_dependency "smarter_csv", "~> 1.1.4"
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.12"
30
30
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsr_group
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.0
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-12-06 00:00:00.000000000 Z
11
+ date: 2017-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smarter_csv
@@ -125,7 +125,7 @@ require_paths:
125
125
  - lib
126
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - "~>"
128
+ - - ">="
129
129
  - !ruby/object:Gem::Version
130
130
  version: '2.0'
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement