zanders 2.3.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zanders/base.rb +0 -2
- data/lib/zanders/catalog.rb +26 -53
- data/lib/zanders/inventory.rb +16 -23
- data/lib/zanders/version.rb +1 -1
- data/zanders.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89bbfb0b8419f723b3961add32b0ab0dc1b6c70a
|
4
|
+
data.tar.gz: 0a8cbe3047e4e1331423f66d7b7b95513419c91e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74ed395a7d1f728a9f4d0c2f65d8ecc4ce552b4f266e86fff6a15034945a2c4b81a822b81b6d4f3bbb2465005228d8fa00bbc56c581c2a1bdcd01836aba92c93
|
7
|
+
data.tar.gz: 66a084e8ef02b7acb4211a27c38baf098cdbd44cc3dcca31e765aa82f9dbf9966cd56807daf9ca279ea62c6a540f47d16a3219e87d8a3e8e671cd9111bf2c48e
|
data/lib/zanders/base.rb
CHANGED
data/lib/zanders/catalog.rb
CHANGED
@@ -1,71 +1,55 @@
|
|
1
1
|
module Zanders
|
2
2
|
class Catalog < Base
|
3
3
|
|
4
|
-
CATALOG_FILENAME
|
4
|
+
CATALOG_FILENAME = 'zandersinv.xml'
|
5
|
+
ITEM_NODE_NAME = 'ZandersDataOut'
|
5
6
|
|
6
7
|
def initialize(options = {})
|
7
8
|
requires!(options, :username, :password)
|
8
9
|
@options = options
|
9
10
|
end
|
10
11
|
|
11
|
-
def self.all(
|
12
|
+
def self.all(options = {}, &block)
|
12
13
|
requires!(options, :username, :password)
|
13
|
-
new(options).all
|
14
|
+
new(options).all &block
|
14
15
|
end
|
15
16
|
|
16
|
-
def all(
|
17
|
-
tempfile
|
18
|
-
xml_doc = Nokogiri::XML(tempfile.open)
|
17
|
+
def all(&block)
|
18
|
+
tempfile = get_file(CATALOG_FILENAME)
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
Nokogiri::XML::Reader.from_io(tempfile).each do |node|
|
21
|
+
next unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
|
22
|
+
next unless node.name == ITEM_NODE_NAME
|
23
|
+
|
24
|
+
yield map_hash(Nokogiri::XML::DocumentFragment.parse(node.inner_xml))
|
22
25
|
end
|
23
26
|
|
27
|
+
tempfile.close
|
24
28
|
tempfile.unlink
|
25
29
|
end
|
26
30
|
|
27
31
|
protected
|
28
32
|
|
29
33
|
def map_hash(node)
|
30
|
-
features =
|
31
|
-
|
32
|
-
# product_type = case content_for(node, 'ITEMPRODUCTTYPE')
|
33
|
-
# when 'PD', 'PR'
|
34
|
-
# :ammunition
|
35
|
-
# else
|
36
|
-
# nil
|
37
|
-
# end
|
34
|
+
features = map_features(node)
|
38
35
|
|
39
36
|
{
|
40
|
-
name:
|
41
|
-
upc:
|
42
|
-
item_identifier:
|
43
|
-
quantity:
|
44
|
-
price:
|
45
|
-
short_description:
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
brand: content_for(node, 'ITEMMANUFACTURER'),
|
54
|
-
features: features
|
37
|
+
name: content_for(node, 'ITEMDESCRIPTION'),
|
38
|
+
upc: content_for(node, 'ITEMUPC'),
|
39
|
+
item_identifier: content_for(node, 'ITEMNO'),
|
40
|
+
quantity: content_for(node, 'ITEMQTYAVAIL'),
|
41
|
+
price: content_for(node, 'ITEMPRICE'),
|
42
|
+
short_description: content_for(node, 'ITEMDESCRIPTION'),
|
43
|
+
category: content_for(node, 'ITEMCATEGORYNAME'),
|
44
|
+
mfg_number: content_for(node, 'ITEMMPN'),
|
45
|
+
weight: content_for(node, 'ITEMWEIGHT'),
|
46
|
+
caliber: features[:caliber],
|
47
|
+
map_price: content_for(node, 'ITEMMAPPRICE'),
|
48
|
+
brand: content_for(node, 'ITEMMANUFACTURER'),
|
49
|
+
features: features
|
55
50
|
}
|
56
51
|
end
|
57
52
|
|
58
|
-
def get_description(item_number)
|
59
|
-
description = @descriptions.find { |x| x[0] == item_number }
|
60
|
-
|
61
|
-
if description
|
62
|
-
description = description.last
|
63
|
-
description.slice!("FEATURES")
|
64
|
-
end
|
65
|
-
|
66
|
-
description
|
67
|
-
end
|
68
|
-
|
69
53
|
def map_features(node)
|
70
54
|
features = Hash.new
|
71
55
|
|
@@ -79,16 +63,5 @@ module Zanders
|
|
79
63
|
features.symbolize_keys!
|
80
64
|
end
|
81
65
|
|
82
|
-
def load_descriptions
|
83
|
-
connect(@options) do |ftp|
|
84
|
-
csv_tempfile = Tempfile.new
|
85
|
-
|
86
|
-
ftp.chdir(Zanders.config.ftp_directory)
|
87
|
-
ftp.getbinaryfile('detaildesctext.csv', csv_tempfile.path)
|
88
|
-
|
89
|
-
@descriptions = CSV.read(csv_tempfile, { :col_sep => '~', :quote_char => "\x00" })
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
66
|
end
|
94
67
|
end
|
data/lib/zanders/inventory.rb
CHANGED
@@ -5,13 +5,12 @@ module Zanders
|
|
5
5
|
|
6
6
|
def initialize(options = {})
|
7
7
|
requires!(options, :username, :password)
|
8
|
-
|
9
8
|
@options = options
|
10
9
|
end
|
11
10
|
|
12
|
-
def self.all(
|
11
|
+
def self.all(options = {}, &block)
|
13
12
|
requires!(options, :username, :password)
|
14
|
-
new(options).all
|
13
|
+
new(options).all &block
|
15
14
|
end
|
16
15
|
|
17
16
|
def self.get_quantity_file(options = {})
|
@@ -19,39 +18,33 @@ module Zanders
|
|
19
18
|
new(options).get_quantity_file
|
20
19
|
end
|
21
20
|
|
22
|
-
def self.quantity(
|
23
|
-
requires!(options, :username, :password)
|
24
|
-
new(options).all(chunk_size, &block)
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.get_file(options = {})
|
21
|
+
def self.quantity(options = {}, &block)
|
28
22
|
requires!(options, :username, :password)
|
29
|
-
new(options).
|
23
|
+
new(options).all &block
|
30
24
|
end
|
31
25
|
|
32
|
-
def all(
|
33
|
-
tempfile
|
34
|
-
xml_doc = Nokogiri::XML(tempfile.open)
|
26
|
+
def all(&block)
|
27
|
+
tempfile = get_file(INVENTORY_FILENAME)
|
35
28
|
|
36
|
-
|
37
|
-
map_hash(item)
|
29
|
+
Nokogiri::XML(tempfile).xpath('//ZandersDataOut').each do |item|
|
30
|
+
yield map_hash(item)
|
38
31
|
end
|
39
32
|
|
33
|
+
tempfile.close
|
40
34
|
tempfile.unlink
|
41
35
|
end
|
42
36
|
|
43
37
|
def get_quantity_file
|
44
|
-
inventory_tempfile
|
45
|
-
tempfile
|
46
|
-
xml_doc = Nokogiri::XML(inventory_tempfile.open)
|
38
|
+
inventory_tempfile = get_file(INVENTORY_FILENAME)
|
39
|
+
tempfile = Tempfile.new
|
47
40
|
|
48
|
-
|
41
|
+
Nokogiri::XML(inventory_tempfile).xpath('//ZandersDataOut').each do |item|
|
49
42
|
tempfile.puts("#{content_for(item, 'ITEMNO')},#{content_for(item, 'AVAILABLE')}")
|
50
43
|
end
|
51
44
|
|
45
|
+
inventory_tempfile.close
|
52
46
|
inventory_tempfile.unlink
|
53
47
|
tempfile.close
|
54
|
-
|
55
48
|
tempfile.path
|
56
49
|
end
|
57
50
|
|
@@ -59,9 +52,9 @@ module Zanders
|
|
59
52
|
|
60
53
|
def map_hash(node)
|
61
54
|
{
|
62
|
-
item_identifier:
|
63
|
-
quantity:
|
64
|
-
price:
|
55
|
+
item_identifier: content_for(node, 'ITEMNO'),
|
56
|
+
quantity: content_for(node, 'AVAILABLE'),
|
57
|
+
price: content_for(node, 'ITEMPRICE')
|
65
58
|
}
|
66
59
|
end
|
67
60
|
|
data/lib/zanders/version.rb
CHANGED
data/zanders.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.add_runtime_dependency "smarter_csv", "~> 1.1.4"
|
28
28
|
|
29
|
+
spec.add_development_dependency "activesupport", "~> 5"
|
29
30
|
spec.add_development_dependency "bundler", "~> 1.14"
|
30
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
32
|
spec.add_development_dependency "rspec", "~> 3.3"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zanders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Knight
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.1.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
172
|
version: '0'
|
159
173
|
requirements: []
|
160
174
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
175
|
+
rubygems_version: 2.6.12
|
162
176
|
signing_key:
|
163
177
|
specification_version: 4
|
164
178
|
summary: Ruby library for Zanders
|