Class: Spree::Tax::TaxLocation

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/tax/tax_location.rb

Overview

A class exclusively used as a drop-in replacement for a default tax address. It responds to `:country_id` and `:state_id`.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Spree::Tax::TaxLocation) initialize(country: nil, state: nil)

Create a new TaxLocation object

Parameters:

See Also:

  • Zone.for_address


19
20
21
22
# File 'app/models/spree/tax/tax_location.rb', line 19

def initialize(country: nil, state: nil)
  @country_id = country && country.id
  @state_id = state && state.id
end

Instance Attribute Details

- (Integer) country_id (readonly)

the ID of a Spree::Country object

Returns:

  • (Integer)

    the current value of country_id



8
9
10
# File 'app/models/spree/tax/tax_location.rb', line 8

def country_id
  @country_id
end

- (Integer) state_id (readonly)

the ID of a Spree::State object

Returns:

  • (Integer)

    the current value of state_id



8
9
10
# File 'app/models/spree/tax/tax_location.rb', line 8

def state_id
  @state_id
end

Instance Method Details

- (Object) ==(other)



24
25
26
# File 'app/models/spree/tax/tax_location.rb', line 24

def ==(other)
  state_id == other.state_id && country_id == other.country_id
end

- (Object) country



28
29
30
# File 'app/models/spree/tax/tax_location.rb', line 28

def country
  Spree::Country.find_by(id: country_id)
end

- (Boolean) empty?

Returns:

  • (Boolean)


32
33
34
# File 'app/models/spree/tax/tax_location.rb', line 32

def empty?
  country_id.nil? && state_id.nil?
end