Class: BillerBotResource::Invoice

Inherits:
Resource
  • Object
show all
Defined in:
lib/biller_bot_resource/invoice.rb

Defined Under Namespace

Classes: Status

Instance Method Summary collapse

Methods inherited from Resource

#cache_key, config, configure, #initialize, instantiate_collection, query_string

Constructor Details

This class inherits a constructor from BillerBotResource::Resource

Instance Method Details

#line_itemsObject



15
16
17
18
# File 'lib/biller_bot_resource/invoice.rb', line 15

def line_items
  @attributes[:line_items] ||= []
  @attributes[:line_items]
end

#locationsObject



10
11
12
13
# File 'lib/biller_bot_resource/invoice.rb', line 10

def locations
  @attributes[:locations] ||= []
  @attributes[:locations]
end

#save(*args) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/biller_bot_resource/invoice.rb', line 20

def save(*args)
  line_items = Array.wrap(@attributes.delete(:line_items)).compact
  locations = Array.wrap(@attributes.delete(:locations)).compact
  @attributes[:line_items_attributes] = line_items unless line_items.empty?
  @attributes[:locations_attributes] = locations unless locations.empty?
  super
end

#total_chargeObject



28
29
30
# File 'lib/biller_bot_resource/invoice.rb', line 28

def total_charge
  line_items.map(&:total_charge).inject(:+) || 0
end