Class: JSONVAT::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/json_vat/country.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Country

Returns a new instance of Country.



6
7
8
# File 'lib/json_vat/country.rb', line 6

def initialize(attributes)
  @attributes = attributes
end

Instance Method Details

#codeObject



18
19
20
# File 'lib/json_vat/country.rb', line 18

def code
  @attributes['code']
end

#country_codeObject



14
15
16
# File 'lib/json_vat/country.rb', line 14

def country_code
  @attributes['country_code']
end

#nameObject



10
11
12
# File 'lib/json_vat/country.rb', line 10

def name
  @attributes['name']
end

#period_on(date) ⇒ Object



26
27
28
# File 'lib/json_vat/country.rb', line 26

def period_on(date)
  periods.select { |p| p.effective_from <= date }.sort_by(&:effective_from).last
end

#periodsObject



22
23
24
# File 'lib/json_vat/country.rb', line 22

def periods
  @periods ||= @attributes['periods'].map { |p| Period.new(self, p) }
end

#rate(type = :standard) ⇒ Object



38
39
40
# File 'lib/json_vat/country.rb', line 38

def rate(type = :standard)
  rate_on(Date.today, type)
end

#rate_on(date, type = :standard) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/json_vat/country.rb', line 30

def rate_on(date, type = :standard)
  if period = period_on(date)
    period.rates[type.to_s]
  else
    nil
  end
end