class Sendregning::Invoice
Constants
- OPTIONAL_ATTRIBUTES
- SHIPMENT_ATTRIBUTES
- SHIPMENT_MODES
Attributes
city[RW]
client[RW]
lines[RW]
name[RW]
optional[RW]
shipment[RW]
zip[RW]
Public Class Methods
new(attributes = {})
click to toggle source
# File lib/sendregning/invoice.rb, line 31 def initialize(attributes = {}) update(attributes) @lines = [] end
Public Instance Methods
add_line(line)
click to toggle source
# File lib/sendregning/invoice.rb, line 45 def add_line(line) line = Sendregning::Line.new(line) unless line.is_a?(Sendregning::Line) @lines << line line end
paid?()
click to toggle source
# File lib/sendregning/invoice.rb, line 56 def paid? state == "paid" end
send!()
click to toggle source
Sends an invoice
# File lib/sendregning/invoice.rb, line 52 def send! client.send_invoice(self) end
shipment_mode()
click to toggle source
# File lib/sendregning/invoice.rb, line 60 def shipment_mode mode = (@shipment[:shipment] || :paper).to_sym raise "Invalid shipment mode!" unless SHIPMENT_MODES.keys.include?(mode) SHIPMENT_MODES[mode] end
to_xml(options = {})
click to toggle source
Renders invoice to XML
# File lib/sendregning/invoice.rb, line 68 def to_xml(options = {}) InvoiceSerializer.build(self, options) end
update(attributes = {})
click to toggle source
# File lib/sendregning/invoice.rb, line 36 def update(attributes = {}) @client = attributes[:client] if attributes[:client] @name = attributes[:name] if attributes[:name] @zip = attributes[:zip] if attributes[:zip] @city = attributes[:city] if attributes[:city] self.optional = attributes self.shipment = attributes end
Protected Instance Methods
filter_attributes(attributes, filter)
click to toggle source
# File lib/sendregning/invoice.rb, line 74 def filter_attributes(attributes, filter) attributes.dup.delete_if { |k, _v| !filter.include?(k.to_sym) } end
method_missing(method, *args)
click to toggle source
Calls superclass method
# File lib/sendregning/invoice.rb, line 88 def method_missing(method, *args) if OPTIONAL_ATTRIBUTES.include?(method) @optional[method] elsif SHIPMENT_ATTRIBUTES.include?(method) @shipment[method] else super end end
optional=(attributes)
click to toggle source
# File lib/sendregning/invoice.rb, line 78 def optional=(attributes) @optional ||= {} @optional.merge!(filter_attributes(attributes, OPTIONAL_ATTRIBUTES)) end
shipment=(attributes)
click to toggle source
# File lib/sendregning/invoice.rb, line 83 def shipment=(attributes) @shipment ||= {} @shipment.merge!(filter_attributes(attributes, SHIPMENT_ATTRIBUTES)) end