Sha256: 2a0a99ab29409b269bd1dedc9e38f61daebdc09aba3b3499067088b353a1ff1f
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
module Mousetrap class Invoice < Resource attr_accessor \ :id, :number, :billing_date, :created_at, :amount def initialize(hash = {}) super(self.class.attributes_from_api(hash)) end protected def self.plural_resource_name 'invoices' end def self.singular_resource_name 'invoice' end def attributes { :id => id, :number => number, :billing_date => billing_date, :created_at => created_at, :amount => amount } end def self.attributes_from_api(attributes) { :id => attributes['id'], :number => attributes['number'], :billing_date => attributes['billingDatetime'], :created_at => attributes['createdDatetime'], :amount => attributes['charges']['charge'].class == Array ? attributes['charges']['charge'].inject(0.0) {|sum, c| sum.to_f + (c['eachAmount'].to_f * c['quantity'].to_i)} : attributes['charges']['charge']['eachAmount'].to_f * attributes['charges']['charge']['quantity'].to_i } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
madebyrocket-mousetrap-0.5.3.8 | lib/mousetrap/invoice.rb |