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.



15422
15423
15424
15425
15426
15427
15428
15429
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15422

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::Price) ? x : ::Io::Flow::V0::Models::Price.new(x))
  @total = (x = opts.delete(:total); x.is_a?(::Io::Flow::V0::Models::Price) ? x : ::Io::Flow::V0::Models::Price.new(x))
end

Instance Attribute Details

#item_number ⇒ Object (readonly)

Returns the value of attribute item_number.



15420
15421
15422
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15420

def item_number
  @item_number
end

#price ⇒ Object (readonly)

Returns the value of attribute price.



15420
15421
15422
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15420

def price
  @price
end

#quantity ⇒ Object (readonly)

Returns the value of attribute quantity.



15420
15421
15422
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15420

def quantity
  @quantity
end

#total ⇒ Object (readonly)

Returns the value of attribute total.



15420
15421
15422
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15420

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



15435
15436
15437
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15435

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

#to_hash ⇒ Object



15439
15440
15441
15442
15443
15444
15445
15446
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15439

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

#to_json ⇒ Object



15431
15432
15433
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 15431

def to_json
  JSON.dump(to_hash)
end