Class: Io::Flow::V0::Models::MoneyWithBase

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ MoneyWithBase

Returns a new instance of MoneyWithBase.



38981
38982
38983
38984
38985
38986
38987
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38981

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:currency, :amount, :base], 'MoneyWithBase')
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
  @base = (x = opts.delete(:base); x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.new(x))
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



38979
38980
38981
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38979

def amount
  @amount
end

#baseObject (readonly)

Returns the value of attribute base.



38979
38980
38981
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38979

def base
  @base
end

#currencyObject (readonly)

Returns the value of attribute currency.



38979
38980
38981
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38979

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



38993
38994
38995
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38993

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

#to_hashObject



38997
38998
38999
39000
39001
39002
39003
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38997

def to_hash
  {
    :currency => currency,
    :amount => amount,
    :base => base.to_hash
  }
end

#to_jsonObject



38989
38990
38991
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 38989

def to_json
  JSON.dump(to_hash)
end