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.



29017
29018
29019
29020
29021
29022
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29017

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.



29015
29016
29017
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29015

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



29015
29016
29017
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29015

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



29028
29029
29030
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29028

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

#to_hashObject



29032
29033
29034
29035
29036
29037
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29032

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

#to_jsonObject



29024
29025
29026
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29024

def to_json
  JSON.dump(to_hash)
end