Class: Io::Flow::V0::Models::MoneyWithOptionalBase

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

Used to migrate older models to have a base value, without breaking compatibility

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ MoneyWithOptionalBase

Returns a new instance of MoneyWithOptionalBase.



29550
29551
29552
29553
29554
29555
29556
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29550

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:currency, :amount], 'MoneyWithOptionalBase')
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
  @base = (x = opts.delete(:base); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.new(x)))
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



29548
29549
29550
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29548

def amount
  @amount
end

#baseObject (readonly)

Returns the value of attribute base.



29548
29549
29550
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29548

def base
  @base
end

#currencyObject (readonly)

Returns the value of attribute currency.



29548
29549
29550
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29548

def currency
  @currency
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



29562
29563
29564
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29562

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

#to_hashObject



29566
29567
29568
29569
29570
29571
29572
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29566

def to_hash
  {
    :currency => currency,
    :amount => amount,
    :base => base.nil? ? nil : base.to_hash
  }
end

#to_jsonObject



29558
29559
29560
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 29558

def to_json
  JSON.dump(to_hash)
end