bill_hicks 1.3.10 → 2.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: 497eff185ebe572e87bc0470a5d454a53eace4d6
4
- data.tar.gz: 2591aaef3445b2742231a4ea1a16b29f90c5f39a
3
+ metadata.gz: 0c8dd7c7f41c6d1042d4be6fe55b875065f55829
4
+ data.tar.gz: 57959c6ad5fff327913a59bc7da9b5a2d6f0771d
5
5
  SHA512:
6
- metadata.gz: 33b6959cfb6f06f96329ed846a792f7f80ad4c45488e7823031cfde294dda7634409abd65c38ecbb163e37f0b06d18901ee49a721cff3d2d776e4e9ca2aa8b23
7
- data.tar.gz: 0160b807ae28d98986946df2866544e452e1e9f20e46b9cfa1f4939a17e26d1949acdd2ef40f40340e29ae480dfd7e2bffa5d0d594209450478f0f546c54e487
6
+ metadata.gz: 5970c5b09ac70ef3d94974311c5ca1fe8155de8b0098d945dd7a517a0969d494bc3db916f59c83637fca760bf73d0cd1dc020b34554491c9c28c887016b5a6f2
7
+ data.tar.gz: a63f6dbd35d7cb0497c6fbc1ec00b359ce003fafbd2af813242980f0bafadbba74c5f3192e8692e0ed0f914811a958125e89f1cf6c0eb30daa563e0e849692fa
@@ -5,12 +5,8 @@ module BillHicks
5
5
  requires!(options, :username, :password)
6
6
 
7
7
  Net::FTP.open(BillHicks.config.ftp_host, options[:username], options[:password]) do |ftp|
8
- begin
9
- ftp.passive = true
10
- yield ftp
11
- ensure
12
- ftp.close
13
- end
8
+ ftp.passive = true
9
+ yield ftp
14
10
  end
15
11
  rescue Net::FTPPermError
16
12
  raise BillHicks::NotAuthenticated
@@ -39,11 +35,7 @@ module BillHicks
39
35
  # Instance methods become class methods through inheritance
40
36
  def connect(options)
41
37
  self.class.connect(options) do |ftp|
42
- begin
43
- yield ftp
44
- ensure
45
- ftp.close
46
- end
38
+ yield ftp
47
39
  end
48
40
  end
49
41
 
@@ -134,7 +134,6 @@ module BillHicks
134
134
  { prefix: 'FED', company: 'Federal' },
135
135
  { prefix: 'IND', company: 'Federal' },
136
136
  { prefix: 'FIO', company: 'Fiocchi' },
137
- { prefix: 'FO', company: 'Freedom Ordnance' },
138
137
  { prefix: 'WILL', company: 'Williams Gun Sight Company' },
139
138
  { prefix: 'FC', company: 'Flippin Critters' },
140
139
  { prefix: 'FLITZ', company: 'Flitz' },
@@ -25,70 +25,86 @@ module BillHicks
25
25
  @options = options
26
26
  end
27
27
 
28
- def self.all(options = {})
28
+ def self.all(chunk_size = 15, options = {}, &block)
29
29
  requires!(options, :username, :password)
30
- new(options).all
30
+ new(options).all(chunk_size, &block)
31
31
  end
32
32
 
33
- def self.process_as_chunks(size = 15, options = {}, &block)
34
- requires!(options, :username, :password)
35
- new(options).process_as_chunks(size, &block)
36
- end
37
-
38
- # Returns an array of hashes with the catalog item details.
39
- def all
40
- catalog = []
41
-
33
+ def all(chunk_size, &block)
42
34
  connect(@options) do |ftp|
35
+ csv_tempfile = Tempfile.new
36
+
43
37
  ftp.chdir(BillHicks.config.top_level_dir)
38
+ ftp.getbinaryfile(CATALOG_FILENAME, csv_tempfile.path)
39
+
40
+ SmarterCSV.process(csv_tempfile, {
41
+ :chunk_size => chunk_size,
42
+ :force_utf8 => true,
43
+ :convert_values_to_numeric => false,
44
+ :key_mapping => {
45
+ :universal_product_code => :upc,
46
+ :product_name => :name,
47
+ :product_weight => :weight,
48
+ :product_price => :price,
49
+ :category_description => :category
50
+ }
51
+ }) do |chunk|
52
+ chunk.each do |item|
53
+ item.except!(:category_code)
54
+
55
+ item[:item_identifier] = item[:upc]
56
+ item[:brand] = BillHicks::BrandConverter.convert(item[:name])
44
57
 
45
- lines = ftp.gettextfile(CATALOG_FILENAME, nil)
58
+ if item[:long_description].present?
59
+ features = self.parse_features(item[:long_description])
46
60
 
47
- CSV.parse(lines, headers: :first_row) do |row|
48
- row_hash = {}
61
+ if features[:action].present?
62
+ item[:action] = features[:action]
49
63
 
50
- # Turn the row into a hash with header names as symbolized keys.
51
- row.each { |r| row_hash[r.first.to_sym] = r.last }
64
+ features.delete(:action)
65
+ elsif features[:caliber].present?
66
+ item[:caliber] = features[:caliber]
52
67
 
53
- # Alias the ':universal_product_code' as ':upc'.
54
- row_hash[:upc] = row_hash[:universal_product_code]
68
+ features.delete(:caliber)
69
+ elsif features[:weight].present?
70
+ item[:weight] = features[:weight]
55
71
 
56
- row_hash[:brand_name] = BillHicks::BrandConverter.convert(row_hash[:product_name])
72
+ features.delete(:weight)
73
+ end
57
74
 
58
- catalog << row_hash
75
+ item[:features] = features
76
+ end
77
+ end
78
+
79
+ yield(chunk)
59
80
  end
60
81
  end
61
-
62
- catalog
63
82
  end
64
83
 
65
- # Streams csv and chunks it
66
- #
67
- # @size integer The number of items in each chunk
68
- def process_as_chunks(size, &block)
69
- connect(@options) do |ftp|
70
- tempfile = Tempfile.new
84
+ protected
71
85
 
72
- ftp.chdir(BillHicks.config.top_level_dir)
73
- ftp.getbinaryfile(CATALOG_FILENAME, tempfile.path)
86
+ def parse_features(text)
87
+ features = Hash.new
88
+ text = text.split("-")
89
+ permitted_features = ['weight', 'caliber', 'action', 'mount', 'finish', 'length', 'diameter', 'rail', 'trigger', 'barrel length', 'silencer mount', 'barrel', 'stock', 'internal bore', 'thread pitch', 'dimensions', 'bulb type', 'bezel diameter', 'output max', 'battery type', 'mount type', 'waterproof rating', 'operating temperature']
74
90
 
75
- smart_options = {
76
- chunk_size: size,
77
- key_mapping: { universal_product_code: :upc },
78
- force_utf8: true,
79
- convert_values_to_numeric: false
80
- }
91
+ text.each do |feature|
92
+ if feature.include?(':') && feature.length <= 45
93
+ key, value = feature.split(':')
81
94
 
82
- SmarterCSV.process(File.open(tempfile, "r:iso-8859-1"), smart_options) do |chunk|
83
- chunk.each do |item|
84
- item[:brand_name] = BillHicks::BrandConverter.convert(item[:product_name])
95
+ if key.nil? || value.nil?
96
+ next
85
97
  end
86
98
 
87
- yield(chunk)
88
- end
99
+ key, value = key.strip.downcase, value.strip
89
100
 
90
- tempfile.unlink
101
+ if permitted_features.include?(key)
102
+ features[key.gsub(" ", "_")] = value
103
+ end
104
+ end
91
105
  end
106
+
107
+ features
92
108
  end
93
109
 
94
110
  end
@@ -15,62 +15,43 @@ module BillHicks
15
15
  @options = options
16
16
  end
17
17
 
18
- def self.all(options = {})
18
+ def self.all(chunk_size = 15, options = {}, &block)
19
19
  requires!(options, :username, :password)
20
- new(options).all
20
+ new(options).all(chunk_size, &block)
21
21
  end
22
22
 
23
- def self.process_as_chunks(size = 15, options = {}, &block)
23
+ def self.quantities(chunk_size = 15, options = {}, &block)
24
24
  requires!(options, :username, :password)
25
- new(options).process_as_chunks(size, &block)
25
+ new(options).quantities(chunk_size, &block)
26
26
  end
27
27
 
28
- # Returns an array of hashes with the inventory item details.
29
- def all
30
- inventory = []
31
-
32
- connect(@options) do |ftp|
33
- ftp.chdir(BillHicks.config.top_level_dir)
34
-
35
- lines = ftp.gettextfile(INVENTORY_FILENAME, nil)
36
-
37
- CSV.parse(lines, headers: :first_row) do |row|
38
- inventory << {
39
- brand_name: BillHicks::BrandConverter.convert(row.fetch('Product')),
40
- product: row.fetch('Product'),
41
- upc: row.fetch('UPC'),
42
- quantity: (Integer(row.fetch('Qty Avail')) rescue 0)
43
- }
44
- end
45
- end
46
-
47
- inventory
48
- end
49
-
50
- # Streams csv and chunks it
51
- #
52
- # @size integer The number of items in each chunk
53
- def process_as_chunks(size, &block)
28
+ def all(chunk_size, &block)
54
29
  connect(@options) do |ftp|
55
- tempfile = Tempfile.new
56
-
57
- ftp.chdir(BillHicks.config.top_level_dir)
58
- ftp.getbinaryfile(INVENTORY_FILENAME, tempfile.path)
59
-
60
- smart_options = {
61
- chunk_size: size,
62
- key_mapping: { qty_avail: :quantity },
63
- force_utf8: true,
64
- convert_values_to_numeric: false
65
- }
66
-
67
- SmarterCSV.process(tempfile, smart_options) do |chunk|
68
- yield(chunk)
30
+ begin
31
+ csv_tempfile = Tempfile.new
32
+
33
+ ftp.chdir(BillHicks.config.top_level_dir)
34
+ ftp.getbinaryfile(INVENTORY_FILENAME, csv_tempfile.path)
35
+
36
+ SmarterCSV.process(csv_tempfile, {
37
+ :chunk_size => chunk_size,
38
+ :force_utf8 => true,
39
+ :convert_values_to_numeric => false,
40
+ :key_mapping => {
41
+ :qty_avail => :quantity,
42
+ :upc => :item_identifier
43
+ }
44
+ }) do |chunk|
45
+ chunk.each do |item|
46
+ item.except!(:product)
47
+ end
48
+
49
+ yield(chunk)
50
+ end
51
+ ensure
52
+ ftp.close
69
53
  end
70
-
71
- tempfile.unlink
72
54
  end
73
55
  end
74
-
75
56
  end
76
57
  end
@@ -1,3 +1,3 @@
1
1
  module BillHicks
2
- VERSION = '1.3.10'.freeze
2
+ VERSION = '2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bill_hicks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.10
4
+ version: '2.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: 2018-04-03 00:00:00.000000000 Z
11
+ date: 2017-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smarter_csv
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  requirements: []
117
117
  rubyforge_project:
118
- rubygems_version: 2.6.12
118
+ rubygems_version: 2.5.1
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Ruby library for Bill Hicks ERP system