Class: ActiveTax::Tax

Inherits:
Object
  • Object
show all
Defined in:
lib/active_tax/tax.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ Tax

Returns a new instance of Tax.


10
11
12
13
14
15
# File 'lib/active_tax/tax.rb', line 10

def initialize(address)
  self.state = address[:state]
  self.address = address

  determine_state_api
end

Instance Attribute Details

#addressObject

Returns the value of attribute address


3
4
5
# File 'lib/active_tax/tax.rb', line 3

def address
  @address
end

#api_classObject

Returns the value of attribute api_class


3
4
5
# File 'lib/active_tax/tax.rb', line 3

def api_class
  @api_class
end

#stateObject

Returns the value of attribute state


3
4
5
# File 'lib/active_tax/tax.rb', line 3

def state
  @state
end

Class Method Details

.rate(address = {}) ⇒ Object

Raises:

  • (StandardError)

5
6
7
8
# File 'lib/active_tax/tax.rb', line 5

def self.rate(address={})
  raise StandardError, "You must provide a state to use ActiveTax::Tax.rate" unless address[:state]
  self.new(address).rate
end

Instance Method Details

#location_codeObject


29
30
31
# File 'lib/active_tax/tax.rb', line 29

def location_code
  tax && tax.location_code
end

#rateObject


25
26
27
# File 'lib/active_tax/tax.rb', line 25

def rate
  tax && tax.rate
end

#rate_from_address(address = {}) ⇒ Object


17
18
19
# File 'lib/active_tax/tax.rb', line 17

def rate_from_address(address={})
  raise "#rate_from_address is deprecated. Use #rate instead."
end

#result_codeObject


33
34
35
# File 'lib/active_tax/tax.rb', line 33

def result_code
  tax && tax.result_code
end

#taxObject


21
22
23
# File 'lib/active_tax/tax.rb', line 21

def tax
  @tax ||= self.api_class.tax(address)
end