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.



38372
38373
38374
38375
38376
38377
38378
38379
38380
38381
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38372

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



38370
38371
38372
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38370

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id.



38370
38371
38372
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38370

def id
  @id
end

#item_numberObject (readonly)

Returns the value of attribute item_number.



38370
38371
38372
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38370

def item_number
  @item_number
end

#priceObject (readonly)

Returns the value of attribute price.



38370
38371
38372
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38370

def price
  @price
end

#quantityObject (readonly)

Returns the value of attribute quantity.



38370
38371
38372
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38370

def quantity
  @quantity
end

#totalObject (readonly)

Returns the value of attribute total.



38370
38371
38372
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38370

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



38387
38388
38389
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38387

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

#to_hashObject



38391
38392
38393
38394
38395
38396
38397
38398
38399
38400
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38391

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

#to_jsonObject



38383
38384
38385
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38383

def to_json
  JSON.dump(to_hash)
end