Class: BillHicks::ResponseFile
- Defined in:
- lib/bill_hicks/response_file.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Class Method Summary collapse
-
.all(ftp) ⇒ Object
Return list of ‘855 Purchase Order Acknowledgement’ files.
Instance Method Summary collapse
-
#ack? ⇒ Boolean
Is the file a ‘855 Purchase Order Acknowledgement’?.
-
#asn? ⇒ Boolean
Is the file a ‘856 Advance Shipping Notice’?.
-
#content ⇒ Object
Use ‘#gettextfile’ to read file contents as a string.
-
#initialize(ftp, options = {}) ⇒ ResponseFile
constructor
A new instance of ResponseFile.
-
#to_json ⇒ Object
Convert to easily readable key-value pairs.
Methods inherited from Base
Constructor Details
#initialize(ftp, options = {}) ⇒ ResponseFile
Returns a new instance of ResponseFile.
10 11 12 13 14 15 16 |
# File 'lib/bill_hicks/response_file.rb', line 10 def initialize(ftp, = {}) requires!(, :username, :password, :filename) @credentials = .select { |k, v| [:username, :password].include?(k) } @filename = [:filename] @ftp = ftp end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
4 5 6 |
# File 'lib/bill_hicks/response_file.rb', line 4 def credentials @credentials end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/bill_hicks/response_file.rb', line 5 def filename @filename end |
Class Method Details
.all(ftp) ⇒ Object
Return list of ‘855 Purchase Order Acknowledgement’ files
21 22 23 |
# File 'lib/bill_hicks/response_file.rb', line 21 def self.all(ftp) ftp.nlst("*.txt") end |
Instance Method Details
#ack? ⇒ Boolean
Is the file a ‘855 Purchase Order Acknowledgement’?
26 27 28 |
# File 'lib/bill_hicks/response_file.rb', line 26 def ack? filename.downcase.start_with?("ack") end |
#asn? ⇒ Boolean
Is the file a ‘856 Advance Shipping Notice’?
31 32 33 |
# File 'lib/bill_hicks/response_file.rb', line 31 def asn? filename.downcase.start_with?("asn") end |
#content ⇒ Object
Use ‘#gettextfile’ to read file contents as a string
36 37 38 39 40 41 42 |
# File 'lib/bill_hicks/response_file.rb', line 36 def content return @content if @content @content = @ftp.gettextfile(@filename, nil) @content end |
#to_json ⇒ Object
Convert to easily readable key-value pairs
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bill_hicks/response_file.rb', line 45 def to_json if corrupt_asn? CSV.parse(content.gsub("Price|", ""), headers: true, col_sep: "|"). map { |x| x.to_h }. group_by { |x| x["PO Number"] } else CSV.parse(content, headers: true, col_sep: "|"). map { |x| x.to_h }. group_by { |x| x["PO Number"] } end end |