Class: Io::Flow::V0::Models::Price

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

Overview

Represents an amount-currency pair for a basic price

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Price

Returns a new instance of Price.



18137
18138
18139
18140
18141
18142
18143
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18137

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:amount, :currency, :label], 'Price')
  @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String)
end

Instance Attribute Details

#amount ⇒ Object (readonly)

Returns the value of attribute amount.



18135
18136
18137
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18135

def amount
  @amount
end

#currency ⇒ Object (readonly)

Returns the value of attribute currency.



18135
18136
18137
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18135

def currency
  @currency
end

#label ⇒ Object (readonly)

Returns the value of attribute label.



18135
18136
18137
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18135

def label
  @label
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



18149
18150
18151
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18149

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

#to_hash ⇒ Object



18153
18154
18155
18156
18157
18158
18159
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18153

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

#to_json ⇒ Object



18145
18146
18147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18145

def to_json
  JSON.dump(to_hash)
end