Class: TaxJp::ConsumptionTax
- Inherits:
-
Object
- Object
- TaxJp::ConsumptionTax
- Defined in:
- lib/tax_jp/consumption_tax.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#local_reduced ⇒ Object
readonly
Returns the value of attribute local_reduced.
-
#national ⇒ Object
readonly
Returns the value of attribute national.
-
#national_reduced ⇒ Object
readonly
Returns the value of attribute national_reduced.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#total_reduced ⇒ Object
readonly
Returns the value of attribute total_reduced.
-
#valid_from ⇒ Object
readonly
Returns the value of attribute valid_from.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(valid_from, values) ⇒ ConsumptionTax
constructor
A new instance of ConsumptionTax.
- #local_percent ⇒ Object
- #local_reduced_percent ⇒ Object
- #national_percent ⇒ Object
- #national_reduced_percent ⇒ Object
- #total_percent ⇒ Object
- #total_reduced_percent ⇒ Object
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
#local ⇒ Object (readonly)
Returns the value of attribute local.
9 10 11 |
# File 'lib/tax_jp/consumption_tax.rb', line 9 def local @local end |
#local_reduced ⇒ Object (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 |
#national ⇒ Object (readonly)
Returns the value of attribute national.
9 10 11 |
# File 'lib/tax_jp/consumption_tax.rb', line 9 def national @national end |
#national_reduced ⇒ Object (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 |
#total ⇒ Object (readonly)
Returns the value of attribute total.
9 10 11 |
# File 'lib/tax_jp/consumption_tax.rb', line 9 def total @total end |
#total_reduced ⇒ Object (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_from ⇒ Object (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
.all ⇒ Object
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, = {}) 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 [:percent] ret *= 100 end ret end |
Instance Method Details
#local_percent ⇒ Object
52 53 54 |
# File 'lib/tax_jp/consumption_tax.rb', line 52 def local_percent local * 100 end |
#local_reduced_percent ⇒ Object
64 65 66 |
# File 'lib/tax_jp/consumption_tax.rb', line 64 def local_reduced_percent local_reduced * 100 end |
#national_percent ⇒ Object
48 49 50 |
# File 'lib/tax_jp/consumption_tax.rb', line 48 def national_percent national * 100 end |
#national_reduced_percent ⇒ Object
60 61 62 |
# File 'lib/tax_jp/consumption_tax.rb', line 60 def national_reduced_percent national_reduced * 100 end |
#total_percent ⇒ Object
56 57 58 |
# File 'lib/tax_jp/consumption_tax.rb', line 56 def total_percent total * 100 end |
#total_reduced_percent ⇒ Object
68 69 70 |
# File 'lib/tax_jp/consumption_tax.rb', line 68 def total_reduced_percent total_reduced * 100 end |