Class: Io::Flow::V0::Models::Price

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

Overview

Represents an amount-currency pair for a basic price

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Price

Returns a new instance of Price.



59815
59816
59817
59818
59819
59820
59821
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 59815

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:amount, :currency, :label], 'Price')
  @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



59813
59814
59815
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 59813

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



59813
59814
59815
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 59813

def currency
  @currency
end

#labelObject (readonly)

Returns the value of attribute label.



59813
59814
59815
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 59813

def label
  @label
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



59827
59828
59829
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 59827

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

#to_hashObject



59831
59832
59833
59834
59835
59836
59837
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 59831

def to_hash
  {
    :amount => amount,
    :currency => currency,
    :label => label
  }
end

#to_jsonObject



59823
59824
59825
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 59823

def to_json
  JSON.dump(to_hash)
end