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.



16327
16328
16329
16330
16331
16332
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16327

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

#amount ⇒ Object (readonly)

Returns the value of attribute amount.



16325
16326
16327
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16325

def amount
  @amount
end

#currency ⇒ Object (readonly)

Returns the value of attribute currency.



16325
16326
16327
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16325

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



16338
16339
16340
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16338

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

#to_hash ⇒ Object



16342
16343
16344
16345
16346
16347
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16342

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

#to_json ⇒ Object



16334
16335
16336
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 16334

def to_json
  JSON.dump(to_hash)
end