Class: Io::Flow::V0::Models::OrderSummaryLineItem

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ OrderSummaryLineItem

Returns a new instance of OrderSummaryLineItem.



41510
41511
41512
41513
41514
41515
41516
41517
41518
41519
41520
41521
41522
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41510

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:item, :quantity, :total, :price_attributes], 'OrderSummaryLineItem')
  @id = (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, String))
  @item = (x = opts.delete(:item); x.is_a?(::Io::Flow::V0::Models::OrderSummaryItem) ? x : ::Io::Flow::V0::Models::OrderSummaryItem.new(x))
  @quantity = HttpClient::Preconditions.assert_class('quantity', opts.delete(:quantity), Integer)
  @discount = (x = opts.delete(:discount); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Price) ? x : ::Io::Flow::V0::Models::Price.new(x)))
  @tax = (x = opts.delete(:tax); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderSummaryLevy) ? x : ::Io::Flow::V0::Models::OrderSummaryLevy.new(x)))
  @duty = (x = opts.delete(:duty); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderSummaryLevy) ? x : ::Io::Flow::V0::Models::OrderSummaryLevy.new(x)))
  @total = (x = opts.delete(:total); x.is_a?(::Io::Flow::V0::Models::Price) ? x : ::Io::Flow::V0::Models::Price.new(x))
  @price_attributes = HttpClient::Preconditions.assert_class('price_attributes', opts.delete(:price_attributes), Hash).inject({}) { |h, d| h[d[0]] = (x = d[1]; x.is_a?(::Io::Flow::V0::Models::Price) ? x : ::Io::Flow::V0::Models::Price.new(x)); h }
  @attributes = (x = opts.delete(:attributes); x.nil? ? nil : HttpClient::Preconditions.assert_class('attributes', x, Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('attributes', d[1], String); h })
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def attributes
  @attributes
end

#discountObject (readonly)

Returns the value of attribute discount.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def discount
  @discount
end

#dutyObject (readonly)

Returns the value of attribute duty.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def duty
  @duty
end

#idObject (readonly)

Returns the value of attribute id.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def id
  @id
end

#itemObject (readonly)

Returns the value of attribute item.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def item
  @item
end

#price_attributesObject (readonly)

Returns the value of attribute price_attributes.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def price_attributes
  @price_attributes
end

#quantityObject (readonly)

Returns the value of attribute quantity.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def quantity
  @quantity
end

#taxObject (readonly)

Returns the value of attribute tax.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def tax
  @tax
end

#totalObject (readonly)

Returns the value of attribute total.



41508
41509
41510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41508

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



41528
41529
41530
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41528

def copy(incoming={})
  OrderSummaryLineItem.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



41532
41533
41534
41535
41536
41537
41538
41539
41540
41541
41542
41543
41544
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41532

def to_hash
  {
    :id => id,
    :item => item.to_hash,
    :quantity => quantity,
    :discount => discount.nil? ? nil : discount.to_hash,
    :tax => tax.nil? ? nil : tax.to_hash,
    :duty => duty.nil? ? nil : duty.to_hash,
    :total => total.to_hash,
    :price_attributes => price_attributes.inject({}) { |hash, o| hash[o[0]] = o[1].nil? ? nil : o[1].to_hash; hash },
    :attributes => attributes.nil? ? nil : attributes
  }
end

#to_jsonObject



41524
41525
41526
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41524

def to_json
  JSON.dump(to_hash)
end