Class: Io::Flow::V0::Models::Duty

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

Overview

Represents a simple model of duties that apply to a given item / trade lane.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Duty

Returns a new instance of Duty.



9653
9654
9655
9656
9657
9658
9659
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9653

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:rate, :components], 'Duty')
  @rate = HttpClient::Preconditions.assert_class('rate', HttpClient::Helper.to_big_decimal(opts.delete(:rate)), BigDecimal)
  @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)) }
  @deminimus = (x = opts.delete(:deminimus); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Deminimus) ? x : ::Io::Flow::V0::Models::Deminimus.from_json(x)))
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



9651
9652
9653
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9651

def components
  @components
end

#deminimusObject (readonly)

Returns the value of attribute deminimus.



9651
9652
9653
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9651

def deminimus
  @deminimus
end

#rateObject (readonly)

Returns the value of attribute rate.



9651
9652
9653
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9651

def rate
  @rate
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



9665
9666
9667
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9665

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

#to_hashObject



9669
9670
9671
9672
9673
9674
9675
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9669

def to_hash
  {
    :rate => rate,
    :components => components.map { |o| o.value },
    :deminimus => deminimus.nil? ? nil : deminimus.to_hash
  }
end

#to_jsonObject



9661
9662
9663
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 9661

def to_json
  JSON.dump(to_hash)
end