Class: Io::Flow::V0::Models::OrderPriceDetail

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

Overview

Represents a top-level order price detail, e.g. ‘Subtotal’ or ‘VAT’.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ OrderPriceDetail

Returns a new instance of OrderPriceDetail.



31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31068

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:key, :currency, :amount, :label, :base, :components], 'OrderPriceDetail')
  @key = (x = opts.delete(:key); x.is_a?(::Io::Flow::V0::Models::OrderPriceDetailKey) ? x : ::Io::Flow::V0::Models::OrderPriceDetailKey.apply(x))
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @amount = HttpClient::Preconditions.assert_class('amount', HttpClient::Helper.to_big_decimal(opts.delete(:amount)), BigDecimal)
  @label = HttpClient::Preconditions.assert_class('label', opts.delete(:label), String)
  @base = (x = opts.delete(:base); x.is_a?(::Io::Flow::V0::Models::Price) ? x : ::Io::Flow::V0::Models::Price.new(x))
  @components = HttpClient::Preconditions.assert_class('components', opts.delete(:components), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::OrderPriceDetailComponent) ? x : ::Io::Flow::V0::Models::OrderPriceDetailComponent.new(x)) }
  @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String))
  @rate = (x = opts.delete(:rate); x.nil? ? nil : HttpClient::Preconditions.assert_class('rate', HttpClient::Helper.to_big_decimal(x), BigDecimal))
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



31066
31067
31068
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31066

def amount
  @amount
end

#baseObject (readonly)

Returns the value of attribute base.



31066
31067
31068
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31066

def base
  @base
end

#componentsObject (readonly)

Returns the value of attribute components.



31066
31067
31068
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31066

def components
  @components
end

#currencyObject (readonly)

Returns the value of attribute currency.



31066
31067
31068
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31066

def currency
  @currency
end

#keyObject (readonly)

Returns the value of attribute key.



31066
31067
31068
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31066

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



31066
31067
31068
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31066

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



31066
31067
31068
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31066

def name
  @name
end

#rateObject (readonly)

Returns the value of attribute rate.



31066
31067
31068
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31066

def rate
  @rate
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



31085
31086
31087
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31085

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

#to_hashObject



31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31089

def to_hash
  {
    :key => key.value,
    :currency => currency,
    :amount => amount,
    :label => label,
    :base => base.to_hash,
    :components => components.map { |o| o.to_hash },
    :name => name,
    :rate => rate
  }
end

#to_jsonObject



31081
31082
31083
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 31081

def to_json
  JSON.dump(to_hash)
end