Class: TaxJp::ConsumptionTax

Inherits:
Object
  • Object
show all
Defined in:
lib/tax_jp/consumption_tax.rb

Constant Summary collapse

@@consumption_taxes =
TaxJp::Utils.load_yaml('消費税.yml')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(valid_from, values) ⇒ ConsumptionTax

Returns a new instance of ConsumptionTax.



12
13
14
15
16
17
18
19
20
# File 'lib/tax_jp/consumption_tax.rb', line 12

def initialize(valid_from, values)
  @valid_from = valid_from
  @national = values['national']
  @local = values['local']
  @total = values['total']
  @national_reduced = values['national_reduced']
  @local_reduced = values['local_reduced']
  @total_reduced = values['total_reduced']
end

Instance Attribute Details

#localObject (readonly)

Returns the value of attribute local.



9
10
11
# File 'lib/tax_jp/consumption_tax.rb', line 9

def local
  @local
end

#local_reducedObject (readonly)

Returns the value of attribute local_reduced.



10
11
12
# File 'lib/tax_jp/consumption_tax.rb', line 10

def local_reduced
  @local_reduced
end

#nationalObject (readonly)

Returns the value of attribute national.



9
10
11
# File 'lib/tax_jp/consumption_tax.rb', line 9

def national
  @national
end

#national_reducedObject (readonly)

Returns the value of attribute national_reduced.



10
11
12
# File 'lib/tax_jp/consumption_tax.rb', line 10

def national_reduced
  @national_reduced
end

#totalObject (readonly)

Returns the value of attribute total.



9
10
11
# File 'lib/tax_jp/consumption_tax.rb', line 9

def total
  @total
end

#total_reducedObject (readonly)

Returns the value of attribute total_reduced.



10
11
12
# File 'lib/tax_jp/consumption_tax.rb', line 10

def total_reduced
  @total_reduced
end

#valid_fromObject (readonly)

Returns the value of attribute valid_from.



8
9
10
# File 'lib/tax_jp/consumption_tax.rb', line 8

def valid_from
  @valid_from
end

Class Method Details

.allObject



22
23
24
25
26
27
28
# File 'lib/tax_jp/consumption_tax.rb', line 22

def self.all
  ret = []
  @@consumption_taxes.each do |valid_from, values|
    ret << ConsumptionTax.new(valid_from, values)
  end
  ret
end

.rate_on(date, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tax_jp/consumption_tax.rb', line 30

def self.rate_on(date, options = {})
  if date.is_a?(String)
    date = Date.parse(date)
  end

  ret = 0
  @@consumption_taxes.reverse_each do |valid_from, rate|
    ret = rate['total']
    break if date >= valid_from
  end

  if options[:percent]
    ret *= 100
  end

  ret
end

Instance Method Details

#local_percentObject



52
53
54
# File 'lib/tax_jp/consumption_tax.rb', line 52

def local_percent
  local * 100
end

#local_reduced_percentObject



64
65
66
# File 'lib/tax_jp/consumption_tax.rb', line 64

def local_reduced_percent
  local_reduced * 100
end

#national_percentObject



48
49
50
# File 'lib/tax_jp/consumption_tax.rb', line 48

def national_percent
  national * 100
end

#national_reduced_percentObject



60
61
62
# File 'lib/tax_jp/consumption_tax.rb', line 60

def national_reduced_percent
  national_reduced * 100
end

#total_percentObject



56
57
58
# File 'lib/tax_jp/consumption_tax.rb', line 56

def total_percent
  total * 100
end

#total_reduced_percentObject



68
69
70
# File 'lib/tax_jp/consumption_tax.rb', line 68

def total_reduced_percent
  total_reduced * 100
end