Sha256: db0d9ef5d4e5d6633aac7acd4cda26c32f964da6b8765949cdc0a33e5d101648

Contents?: true

Size: 835 Bytes

Versions: 1

Compression:

Stored size: 835 Bytes

Contents

class DeathAndTaxes::Taxes::Country
  
  def initialize tax_infos
    @taxes = tax_infos['taxes'].collect do |tax|
      Tax.new tax, :country => self
    end
    
    @states = {}
    tax_infos['states'].each do |name, tax|
      @states[name] = Tax.new(tax)
    end
  end
  
  def apply_taxes product, from, to, options = {}
    if from[:country] == to[:country]
      if (state = @states[from[:state]] && state.matches?(from, to))
        state.apply_taxes product, from, to, options
      else
        apply_tax product, from, to, options
      end
    end
    []
  end
  
  private
  def apply_tax product, from, to, options
    options.reverse_merge!({:time => Time.now})
    
    find_tax product, options[:date]
  end
  
  def find_tax product, date
    @taxes.select do |tax|
      tax.period.cover?(date)
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
death_and_taxes-0.0.0 lib/death_and_taxes/taxes/country.rb