bill_hicks 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bill_hicks/response_file.rb +34 -9
- data/lib/bill_hicks/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f742da9e6373d6d8f67e7829b84bf8e4f7976cc
|
4
|
+
data.tar.gz: f1b1cc495b03b9376531024e27a701b99eef4cce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccc7e150e7818cc090abd33fb85296a35f5ccbbfdc3f09b8c2aa301af07990e387678713157a4f0a8a01d32e943e5632455a06612e7be0572cc0583da3e396e6
|
7
|
+
data.tar.gz: 72498c5001ad3422915e36edee6d64efc83cfb0699a9334e8aa863bc756c8e9c37f1d42dc5c3c62872eccdbee0b761e5f89d484003aed4952931a3c0e7b6b6ce
|
@@ -1,15 +1,9 @@
|
|
1
1
|
module BillHicks
|
2
2
|
class ResponseFile < Base
|
3
3
|
|
4
|
-
attr_reader :content
|
5
4
|
attr_reader :credentials
|
6
5
|
attr_reader :filename
|
7
6
|
|
8
|
-
FILE_TYPES = {
|
9
|
-
"ACK" => "Purchase Order Acknowledgement",
|
10
|
-
"ASN" => "Advance Shipping Notice"
|
11
|
-
}
|
12
|
-
|
13
7
|
# @option options [String] :username *required*
|
14
8
|
# @option options [String] :password *required*
|
15
9
|
# @option options [String] :filename *required*
|
@@ -32,6 +26,17 @@ module BillHicks
|
|
32
26
|
end
|
33
27
|
end
|
34
28
|
|
29
|
+
# Is the file a '855 Purchase Order Acknowledgement'?
|
30
|
+
def ack?
|
31
|
+
content.start_with?("ACK")
|
32
|
+
end
|
33
|
+
|
34
|
+
# Is the file a '856 Advance Shipping Notice'?
|
35
|
+
def asn?
|
36
|
+
content.start_with?("ASN")
|
37
|
+
end
|
38
|
+
|
39
|
+
# Use '#gettextfile' to read file contents as a string
|
35
40
|
def content
|
36
41
|
return @content if @content
|
37
42
|
connect(@credentials) do |ftp|
|
@@ -40,10 +45,30 @@ module BillHicks
|
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
48
|
+
# Convert to easily readable key-value pairs
|
43
49
|
def to_json
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
if corrupt_asn?
|
51
|
+
CSV.parse(content.gsub("Price|", ""), headers: true, col_sep: "|").
|
52
|
+
map { |x| x.to_h }.
|
53
|
+
group_by { |x| x["PO Number"] }
|
54
|
+
else
|
55
|
+
CSV.parse(content, headers: true, col_sep: "|").
|
56
|
+
map { |x| x.to_h }.
|
57
|
+
group_by { |x| x["PO Number"] }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def corrupt_asn?
|
64
|
+
return false if ack?
|
65
|
+
lines = content.lines.map(&:chomp)
|
66
|
+
if lines[0].split("|").length != lines[1].split("|").length
|
67
|
+
puts "Notice: ASN file is malformed! (#{filename})"
|
68
|
+
true
|
69
|
+
else
|
70
|
+
false
|
71
|
+
end
|
47
72
|
end
|
48
73
|
|
49
74
|
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: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|