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.



18328
18329
18330
18331
18332
18333
18334
18335
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18328

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)) }
  @deminimis = (x = opts.delete(:deminimis); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Deminimis) ? x : ::Io::Flow::V0::Models::Deminimis.from_json(x)))
  @name = (x = opts.delete(:name); x.nil? ? nil : HttpClient::Preconditions.assert_class('name', x, String))
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



18326
18327
18328
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18326

def components
  @components
end

#deminimisObject (readonly)

Returns the value of attribute deminimis.



18326
18327
18328
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18326

def deminimis
  @deminimis
end

#nameObject (readonly)

Returns the value of attribute name.



18326
18327
18328
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18326

def name
  @name
end

#rateObject (readonly)

Returns the value of attribute rate.



18326
18327
18328
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18326

def rate
  @rate
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



18341
18342
18343
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18341

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

#to_hashObject



18345
18346
18347
18348
18349
18350
18351
18352
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18345

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

#to_jsonObject



18337
18338
18339
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 18337

def to_json
  JSON.dump(to_hash)
end