Class: Io::Flow::V0::Models::OrderSummaryItem

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 = {}) ⇒ OrderSummaryItem

Returns a new instance of OrderSummaryItem.



41588
41589
41590
41591
41592
41593
41594
41595
41596
41597
41598
41599
41600
41601
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41588

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:number, :name, :attributes, :price, :price_attributes], 'OrderSummaryItem')
  @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
  @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
  @description = (x = opts.delete(:description); x.nil? ? nil : HttpClient::Preconditions.assert_class('description', x, String))
  @attributes = HttpClient::Preconditions.assert_class('attributes', opts.delete(:attributes), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::CheckoutItemContentAttribute) ? x : ::Io::Flow::V0::Models::CheckoutItemContentAttribute.new(x)) }
  @image = (x = opts.delete(:image); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderSummaryImage) ? x : ::Io::Flow::V0::Models::OrderSummaryImage.new(x)))
  @price = (x = opts.delete(:price); x.is_a?(::Io::Flow::V0::Models::Price) ? x : ::Io::Flow::V0::Models::Price.new(x))
  @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)))
  @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

#attributesObject (readonly)

Returns the value of attribute attributes.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def attributes
  @attributes
end

#descriptionObject (readonly)

Returns the value of attribute description.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def description
  @description
end

#discountObject (readonly)

Returns the value of attribute discount.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def discount
  @discount
end

#dutyObject (readonly)

Returns the value of attribute duty.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def duty
  @duty
end

#imageObject (readonly)

Returns the value of attribute image.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def image
  @image
end

#nameObject (readonly)

Returns the value of attribute name.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def number
  @number
end

#priceObject (readonly)

Returns the value of attribute price.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def price
  @price
end

#price_attributesObject (readonly)

Returns the value of attribute price_attributes.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def price_attributes
  @price_attributes
end

#taxObject (readonly)

Returns the value of attribute tax.



41586
41587
41588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41586

def tax
  @tax
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



41607
41608
41609
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41607

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

#to_hashObject



41611
41612
41613
41614
41615
41616
41617
41618
41619
41620
41621
41622
41623
41624
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41611

def to_hash
  {
    :number => number,
    :name => name,
    :description => description,
    :attributes => attributes.map { |o| o.to_hash },
    :image => image.nil? ? nil : image.to_hash,
    :price => price.to_hash,
    :discount => discount.nil? ? nil : discount.to_hash,
    :tax => tax.nil? ? nil : tax.to_hash,
    :duty => duty.nil? ? nil : duty.to_hash,
    :price_attributes => price_attributes.inject({}) { |hash, o| hash[o[0]] = o[1].nil? ? nil : o[1].to_hash; hash }
  }
end

#to_jsonObject



41603
41604
41605
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41603

def to_json
  JSON.dump(to_hash)
end