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.



17488
17489
17490
17491
17492
17493
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17488

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.



17486
17487
17488
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17486

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



17486
17487
17488
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17486

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



17499
17500
17501
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17499

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

#to_hashObject



17503
17504
17505
17506
17507
17508
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17503

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

#to_jsonObject



17495
17496
17497
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17495

def to_json
  JSON.dump(to_hash)
end