Class: Io::Flow::V0::Models::Tax

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

Overview

Represents a simple model of taxes that apply to a given item / destination.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Tax

Returns a new instance of Tax.



41684
41685
41686
41687
41688
41689
41690
41691
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41684

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:name, :rate, :components], 'Tax')
  @name = HttpClient::Preconditions.assert_class('name', opts.delete(:name), String)
  @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)))
end

Instance Attribute Details

#componentsObject (readonly)

Returns the value of attribute components.



41682
41683
41684
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41682

def components
  @components
end

#deminimisObject (readonly)

Returns the value of attribute deminimis.



41682
41683
41684
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41682

def deminimis
  @deminimis
end

#nameObject (readonly)

Returns the value of attribute name.



41682
41683
41684
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41682

def name
  @name
end

#rateObject (readonly)

Returns the value of attribute rate.



41682
41683
41684
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41682

def rate
  @rate
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



41697
41698
41699
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41697

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

#to_hashObject



41701
41702
41703
41704
41705
41706
41707
41708
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41701

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

#to_jsonObject



41693
41694
41695
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 41693

def to_json
  JSON.dump(to_hash)
end