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.



32004
32005
32006
32007
32008
32009
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32004

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.



32002
32003
32004
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32002

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



32002
32003
32004
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32002

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



32015
32016
32017
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32015

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

#to_hashObject



32019
32020
32021
32022
32023
32024
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32019

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

#to_jsonObject



32011
32012
32013
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32011

def to_json
  JSON.dump(to_hash)
end