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.



40904
40905
40906
40907
40908
40909
40910
40911
40912
40913
40914
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40904

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:item, :quantity, :total, :price_attributes], 'OrderSummaryLineItem')
  @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 }
end

Instance Attribute Details

#discountObject (readonly)

Returns the value of attribute discount.



40902
40903
40904
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40902

def discount
  @discount
end

#dutyObject (readonly)

Returns the value of attribute duty.



40902
40903
40904
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40902

def duty
  @duty
end

#itemObject (readonly)

Returns the value of attribute item.



40902
40903
40904
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40902

def item
  @item
end

#price_attributesObject (readonly)

Returns the value of attribute price_attributes.



40902
40903
40904
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40902

def price_attributes
  @price_attributes
end

#quantityObject (readonly)

Returns the value of attribute quantity.



40902
40903
40904
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40902

def quantity
  @quantity
end

#taxObject (readonly)

Returns the value of attribute tax.



40902
40903
40904
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40902

def tax
  @tax
end

#totalObject (readonly)

Returns the value of attribute total.



40902
40903
40904
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40902

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



40920
40921
40922
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40920

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

#to_hashObject



40924
40925
40926
40927
40928
40929
40930
40931
40932
40933
40934
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40924

def to_hash
  {
    :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 }
  }
end

#to_jsonObject



40916
40917
40918
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40916

def to_json
  JSON.dump(to_hash)
end