Class: Io::Flow::V0::Models::Money

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

Overview

Money represents an amount in a given currency

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Money

Returns a new instance of Money.



23994
23995
23996
23997
23998
23999
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23994

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

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



23992
23993
23994
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23992

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



23992
23993
23994
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 23992

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



24005
24006
24007
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24005

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

#to_hashObject



24009
24010
24011
24012
24013
24014
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24009

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

#to_jsonObject



24001
24002
24003
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24001

def to_json
  JSON.dump(to_hash)
end