Class: Io::Flow::V0::Models::DeminimisSimple

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

Overview

De Minimis for most common example which includes a value threshold and rules on what components are used in the duty calculation

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Deminimis

from_json, #to_hash

Constructor Details

#initialize(incoming = {}) ⇒ DeminimisSimple

Returns a new instance of DeminimisSimple.



10254
10255
10256
10257
10258
10259
10260
10261
10262
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10254

def initialize(incoming={})
  super(:name => Deminimis::Types::DEMINIMIS_SIMPLE)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:value, :currency, :components, :minimum], 'DeminimisSimple')
  @value = HttpClient::Preconditions.assert_class('value', HttpClient::Helper.to_big_decimal(opts.delete(:value)), BigDecimal)
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @components = HttpClient::Preconditions.assert_class('components', opts.delete(:components), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::LevyComponent) ? x : ::Io::Flow::V0::Models::LevyComponent.apply(x)) }
  @minimum = HttpClient::Preconditions.assert_class('minimum', HttpClient::Helper.to_big_decimal(opts.delete(:minimum)), BigDecimal)
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



10252
10253
10254
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10252

def components
  @components
end

#currencyObject (readonly)

Returns the value of attribute currency.



10252
10253
10254
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10252

def currency
  @currency
end

#minimumObject (readonly)

Returns the value of attribute minimum.



10252
10253
10254
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10252

def minimum
  @minimum
end

#valueObject (readonly)

Returns the value of attribute value.



10252
10253
10254
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10252

def value
  @value
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



10268
10269
10270
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10268

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

#subtype_to_hashObject



10272
10273
10274
10275
10276
10277
10278
10279
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10272

def subtype_to_hash
  {
    :value => value,
    :currency => currency,
    :components => components.map { |o| o.value },
    :minimum => minimum
  }
end

#to_jsonObject



10264
10265
10266
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10264

def to_json
  JSON.dump(to_hash)
end