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.



12628
12629
12630
12631
12632
12633
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12628

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.



12626
12627
12628
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12626

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



12626
12627
12628
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12626

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



12639
12640
12641
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12639

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

#to_hashObject



12643
12644
12645
12646
12647
12648
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12643

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

#to_jsonObject



12635
12636
12637
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12635

def to_json
  JSON.dump(to_hash)
end