Class: Io::Flow::V0::Models::Line

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

Overview

Provides display data for a line item.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Line

Returns a new instance of Line.



28129
28130
28131
28132
28133
28134
28135
28136
28137
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28129

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:item_number, :quantity, :price, :total], 'Line')
  @item_number = HttpClient::Preconditions.assert_class('item_number', opts.delete(:item_number), String)
  @quantity = HttpClient::Preconditions.assert_class('quantity', opts.delete(:quantity), Integer)
  @price = (x = opts.delete(:price); x.is_a?(::Io::Flow::V0::Models::PriceWithBase) ? x : ::Io::Flow::V0::Models::PriceWithBase.new(x))
  @total = (x = opts.delete(:total); x.is_a?(::Io::Flow::V0::Models::PriceWithBase) ? x : ::Io::Flow::V0::Models::PriceWithBase.new(x))
  @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.



28127
28128
28129
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28127

def attributes
  @attributes
end

#item_numberObject (readonly)

Returns the value of attribute item_number.



28127
28128
28129
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28127

def item_number
  @item_number
end

#priceObject (readonly)

Returns the value of attribute price.



28127
28128
28129
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28127

def price
  @price
end

#quantityObject (readonly)

Returns the value of attribute quantity.



28127
28128
28129
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28127

def quantity
  @quantity
end

#totalObject (readonly)

Returns the value of attribute total.



28127
28128
28129
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28127

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



28143
28144
28145
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28143

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

#to_hashObject



28147
28148
28149
28150
28151
28152
28153
28154
28155
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28147

def to_hash
  {
    :item_number => item_number,
    :quantity => quantity,
    :price => price.to_hash,
    :total => total.to_hash,
    :attributes => attributes.nil? ? nil : attributes
  }
end

#to_jsonObject



28139
28140
28141
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 28139

def to_json
  JSON.dump(to_hash)
end