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.



39691
39692
39693
39694
39695
39696
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39691

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.



39689
39690
39691
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39689

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



39689
39690
39691
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39689

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



39702
39703
39704
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39702

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

#to_hashObject



39706
39707
39708
39709
39710
39711
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39706

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

#to_jsonObject



39698
39699
39700
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 39698

def to_json
  JSON.dump(to_hash)
end