Class: Taxedo::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/taxedo/region.rb

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Region

Returns a new instance of Region.



5
6
7
8
# File 'lib/taxedo/region.rb', line 5

def initialize(id)
  @id = id
  @data = YAML.load_file(Taxedo.base_data_path + "regions.yml")['taxedo']['regions'][@id]
end

Instance Method Details

#calculate(amount, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/taxedo/region.rb', line 10

def calculate(amount, options={})
  options = { :on => Time.now, :rule => 'standard', :equations => 'compiled'}.merge(options)

  receipt = Taxedo::Receipt.new(@id, amount)
  receipt.currency = @data['currency']
  receipt.equation_type = equation_type_from_date(options[:on]).nil? ? options[:equations] : equation_type_from_date(options[:on])

  taxes(options[:rule], options[:on]).each do |tax|
    receipt.add_tax tax[0], tax[1]
  end

  return receipt
end