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 +4 -4
- data/lib/bill_hicks/base.rb +3 -11
- data/lib/bill_hicks/brand_converter.rb +0 -1
- data/lib/bill_hicks/catalog.rb +58 -42
- data/lib/bill_hicks/inventory.rb +28 -47
- data/lib/bill_hicks/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c8dd7c7f41c6d1042d4be6fe55b875065f55829
|
4
|
+
data.tar.gz: 57959c6ad5fff327913a59bc7da9b5a2d6f0771d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5970c5b09ac70ef3d94974311c5ca1fe8155de8b0098d945dd7a517a0969d494bc3db916f59c83637fca760bf73d0cd1dc020b34554491c9c28c887016b5a6f2
|
7
|
+
data.tar.gz: a63f6dbd35d7cb0497c6fbc1ec00b359ce003fafbd2af813242980f0bafadbba74c5f3192e8692e0ed0f914811a958125e89f1cf6c0eb30daa563e0e849692fa
|
data/lib/bill_hicks/base.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
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
|
-
|
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' },
|
data/lib/bill_hicks/catalog.rb
CHANGED
@@ -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
|
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
|
-
|
58
|
+
if item[:long_description].present?
|
59
|
+
features = self.parse_features(item[:long_description])
|
46
60
|
|
47
|
-
|
48
|
-
|
61
|
+
if features[:action].present?
|
62
|
+
item[:action] = features[:action]
|
49
63
|
|
50
|
-
|
51
|
-
|
64
|
+
features.delete(:action)
|
65
|
+
elsif features[:caliber].present?
|
66
|
+
item[:caliber] = features[:caliber]
|
52
67
|
|
53
|
-
|
54
|
-
|
68
|
+
features.delete(:caliber)
|
69
|
+
elsif features[:weight].present?
|
70
|
+
item[:weight] = features[:weight]
|
55
71
|
|
56
|
-
|
72
|
+
features.delete(:weight)
|
73
|
+
end
|
57
74
|
|
58
|
-
|
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
|
-
|
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
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
83
|
-
|
84
|
-
item[:brand_name] = BillHicks::BrandConverter.convert(item[:product_name])
|
95
|
+
if key.nil? || value.nil?
|
96
|
+
next
|
85
97
|
end
|
86
98
|
|
87
|
-
|
88
|
-
end
|
99
|
+
key, value = key.strip.downcase, value.strip
|
89
100
|
|
90
|
-
|
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
|
data/lib/bill_hicks/inventory.rb
CHANGED
@@ -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.
|
23
|
+
def self.quantities(chunk_size = 15, options = {}, &block)
|
24
24
|
requires!(options, :username, :password)
|
25
|
-
new(options).
|
25
|
+
new(options).quantities(chunk_size, &block)
|
26
26
|
end
|
27
27
|
|
28
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
data/lib/bill_hicks/version.rb
CHANGED
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:
|
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:
|
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.
|
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
|