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.



29490
29491
29492
29493
29494
29495
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29490

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.



29488
29489
29490
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29488

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



29488
29489
29490
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29488

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



29501
29502
29503
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29501

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

#to_hashObject



29505
29506
29507
29508
29509
29510
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29505

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

#to_jsonObject



29497
29498
29499
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29497

def to_json
  JSON.dump(to_hash)
end