class Sendregning::InvoiceParser
Public Class Methods
new(response, invoice)
click to toggle source
# File lib/sendregning/invoice_parser.rb, line 11 def initialize(response, invoice) @response = response @invoice = invoice end
parse(response, invoice = Sendregning::Invoice.new)
click to toggle source
# File lib/sendregning/invoice_parser.rb, line 6 def parse(response, invoice = Sendregning::Invoice.new) new(response, invoice).parse end
Public Instance Methods
parse()
click to toggle source
# File lib/sendregning/invoice_parser.rb, line 16 def parse attributes = @response["invoices"]["invoice"] # Flatten optional and shipment attributes %w[optional shipment].each do |section| if attributes.key?(section) attributes = attributes.merge(attributes[section]) attributes.delete(section) end end lines = attributes["lines"]["line"] attributes.delete("lines") @invoice.update(stringify_hash(attributes)) @invoice.lines = lines.map do |l| Sendregning::Line.new(stringify_hash(l)) end @invoice end
Protected Instance Methods
stringify_hash(hash)
click to toggle source
# File lib/sendregning/invoice_parser.rb, line 39 def stringify_hash(hash) new_hash = {} hash.each do |key, value| new_hash[key] = value.to_s end new_hash end