bill_hicks 1.1.2 → 1.1.3

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: 3acd6561e4f26a01ea35cb6589802e8fd7518797
4
- data.tar.gz: 917c159dfebdad61b16bccf89ae2182f3cbfb56c
3
+ metadata.gz: 9f742da9e6373d6d8f67e7829b84bf8e4f7976cc
4
+ data.tar.gz: f1b1cc495b03b9376531024e27a701b99eef4cce
5
5
  SHA512:
6
- metadata.gz: 2a7ef2a5f7adf6af9e6d050f62baceb4e39aaacb79539f9083480dd567bdb2c770ceaf0eecca3141a41abaa05293324e06851819296fc80db0d02f5fa0b55aee
7
- data.tar.gz: 3a894f4dae4d6d6072942c5bf1758a9894ad5b53b5becab34181be6e5f77f827bd4328a8c9910480a1d02943b1a53e8e6d3b4886f6277af6b25b83a1a3d80efd
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
- CSV.parse(content, headers: true, col_sep: "|").
45
- map { |x| x.to_h }.
46
- group_by { |x| x["PO Number"] }
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
@@ -1,3 +1,3 @@
1
1
  module BillHicks
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
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.1.2
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-14 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler