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.



24397
24398
24399
24400
24401
24402
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24397

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.



24395
24396
24397
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24395

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



24395
24396
24397
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24395

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



24408
24409
24410
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24408

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

#to_hashObject



24412
24413
24414
24415
24416
24417
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24412

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

#to_jsonObject



24404
24405
24406
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 24404

def to_json
  JSON.dump(to_hash)
end