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.



23885
23886
23887
23888
23889
23890
23891
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23885

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.



23883
23884
23885
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23883

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



23883
23884
23885
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23883

def currency
  @currency
end

#labelObject (readonly)

Returns the value of attribute label.



23883
23884
23885
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23883

def label
  @label
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



23897
23898
23899
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23897

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

#to_hashObject



23901
23902
23903
23904
23905
23906
23907
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23901

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

#to_jsonObject



23893
23894
23895
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23893

def to_json
  JSON.dump(to_hash)
end