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.



50432
50433
50434
50435
50436
50437
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 50432

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.



50430
50431
50432
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 50430

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



50430
50431
50432
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 50430

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



50443
50444
50445
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 50443

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

#to_hashObject



50447
50448
50449
50450
50451
50452
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 50447

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

#to_jsonObject



50439
50440
50441
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 50439

def to_json
  JSON.dump(to_hash)
end