Class: Io::Flow::V0::Models::AllocationLevyComponent

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

Overview

Represents either a VAT or duty component.

Instance Attribute Summary collapse

Attributes inherited from AllocationComponent

#discriminator

Instance Method Summary collapse

Methods inherited from AllocationComponent

from_json, #to_hash

Constructor Details

#initialize(incoming = {}) ⇒ AllocationLevyComponent

Returns a new instance of AllocationLevyComponent.



22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22173

def initialize(incoming={})
  super(:discriminator => AllocationComponent::Types::ALLOCATION_LEVY_COMPONENT)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:key, :total, :rate, :name], 'AllocationLevyComponent')
  @key = (x = opts.delete(:key); x.is_a?(::Io::Flow::V0::Models::OrderPriceDetailComponentKey) ? x : ::Io::Flow::V0::Models::OrderPriceDetailComponentKey.apply(x))
  @total = (x = opts.delete(:total); x.is_a?(::Io::Flow::V0::Models::PriceWithBase) ? x : ::Io::Flow::V0::Models::PriceWithBase.new(x))
  @rate = HttpClient::Preconditions.assert_class('rate', HttpClient::Helper.to_big_decimal(opts.delete(:rate)), BigDecimal)
  @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
  @price = (x = opts.delete(:price); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::PriceWithBase) ? x : ::Io::Flow::V0::Models::PriceWithBase.new(x)))
  @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))
  @basis = (x = opts.delete(:basis); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::MoneyWithBase) ? x : ::Io::Flow::V0::Models::MoneyWithBase.new(x)))
end

Instance Attribute Details

#accuracyObject (readonly)

Returns the value of attribute accuracy.



22171
22172
22173
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22171

def accuracy
  @accuracy
end

#basisObject (readonly)

Returns the value of attribute basis.



22171
22172
22173
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22171

def basis
  @basis
end

#keyObject (readonly)

Returns the value of attribute key.



22171
22172
22173
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22171

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



22171
22172
22173
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22171

def name
  @name
end

#priceObject (readonly)

Returns the value of attribute price.



22171
22172
22173
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22171

def price
  @price
end

#rateObject (readonly)

Returns the value of attribute rate.



22171
22172
22173
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22171

def rate
  @rate
end

#totalObject (readonly)

Returns the value of attribute total.



22171
22172
22173
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22171

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



22190
22191
22192
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22190

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

#subtype_to_hashObject



22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22194

def subtype_to_hash
  {
    :key => key.value,
    :total => total.to_hash,
    :rate => rate.to_f.to_s,
    :name => name,
    :price => price.nil? ? nil : price.to_hash,
    :accuracy => accuracy.value,
    :basis => basis.nil? ? nil : basis.to_hash
  }
end

#to_jsonObject



22186
22187
22188
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 22186

def to_json
  JSON.dump(to_hash)
end