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.



40936
40937
40938
40939
40940
40941
40942
40943
40944
40945
40946
40947
40948
40949
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40936

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))
  @accuracy = (x = (x = opts.delete(:accuracy); x.nil? ? "calculated" : x); x.is_a?(::Io::Flow::V0::Models::PriceAccuracy) ? x : ::Io::Flow::V0::Models::PriceAccuracy.apply(x))
  @rate_label = (x = opts.delete(:rate_label); x.nil? ? nil : HttpClient::Preconditions.assert_class('rate_label', x, String))
end

Instance Attribute Details

#accuracyObject (readonly)

Returns the value of attribute accuracy.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def accuracy
  @accuracy
end

#amountObject (readonly)

Returns the value of attribute amount.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def amount
  @amount
end

#baseObject (readonly)

Returns the value of attribute base.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def base
  @base
end

#componentsObject (readonly)

Returns the value of attribute components.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def components
  @components
end

#currencyObject (readonly)

Returns the value of attribute currency.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def currency
  @currency
end

#keyObject (readonly)

Returns the value of attribute key.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def key
  @key
end

#labelObject (readonly)

Returns the value of attribute label.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def name
  @name
end

#rateObject (readonly)

Returns the value of attribute rate.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def rate
  @rate
end

#rate_labelObject (readonly)

Returns the value of attribute rate_label.



40934
40935
40936
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40934

def rate_label
  @rate_label
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



40955
40956
40957
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40955

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

#to_hashObject



40959
40960
40961
40962
40963
40964
40965
40966
40967
40968
40969
40970
40971
40972
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40959

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

#to_jsonObject



40951
40952
40953
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 40951

def to_json
  JSON.dump(to_hash)
end