Class: Strikeiron::TaxResult

Inherits:
Object
  • Object
show all
Defined in:
lib/strikeiron2/tax_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_values = {}) ⇒ TaxResult

Returns a new instance of TaxResult.



5
6
7
# File 'lib/strikeiron2/tax_result.rb', line 5

def initialize(default_values = {})
  default_values.each { |key, value| self.send "#{key}=", value }
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



3
4
5
# File 'lib/strikeiron2/tax_result.rb', line 3

def from
  @from
end

#tax_valuesObject

Returns the value of attribute tax_values.



3
4
5
# File 'lib/strikeiron2/tax_result.rb', line 3

def tax_values
  @tax_values
end

#toObject

Returns the value of attribute to.



3
4
5
# File 'lib/strikeiron2/tax_result.rb', line 3

def to
  @to
end

#total_taxObject

Returns the value of attribute total_tax.



3
4
5
# File 'lib/strikeiron2/tax_result.rb', line 3

def total_tax
  @total_tax
end

Class Method Details

.from_soap(response) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/strikeiron2/tax_result.rb', line 9

def self.from_soap(response)
  tax_values       = []
  response_records = response[:results][:tax_value_record]
  response_records = [ response_records ] if response_records.is_a?(Hash)

  response_records.each do |record|
    jurisdictions = record[:jurisdictions][:sales_tax_value_jurisdiction]
    jurisdictions = [ jurisdictions ] if jurisdictions.is_a?(Hash)

    tax_values << TaxValue.new(
      :category      => record[:category],
      :category_id   => record[:category_id],
      :tax_amount    => record[:sales_tax_amount].to_f,
      :jurisdictions => jurisdictions.collect { |j| Jurisdiction.new(:fips => j[:fips], :name => j[:name], :tax_amount => j[:sales_tax_amount].to_f) }
    )
  end

  new(
    :from       => Address.new(response[:resolved_from_address]),
    :to         => Address.new(response[:resolved_to_address]),
    :tax_values => tax_values,
    :total_tax  => tax_values.inject(0) { |sum, tax_value| sum + tax_value.tax_amount }
  )
end