class JSONVAT::Country

Public Class Methods

new(attributes) click to toggle source
# File lib/json_vat/country.rb, line 6
def initialize(attributes)
  @attributes = attributes
end

Public Instance Methods

code() click to toggle source
# File lib/json_vat/country.rb, line 18
def code
  @attributes['code']
end
country_code() click to toggle source
# File lib/json_vat/country.rb, line 14
def country_code
  @attributes['country_code']
end
name() click to toggle source
# File lib/json_vat/country.rb, line 10
def name
  @attributes['name']
end
period_on(date) click to toggle source
# 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
periods() click to toggle source
# File lib/json_vat/country.rb, line 22
def periods
  @periods ||= @attributes['periods'].map { |p| Period.new(self, p) }
end
rate(type = :standard) click to toggle source
# File lib/json_vat/country.rb, line 38
def rate(type = :standard)
  rate_on(Date.today, type)
end
rate_on(date, type = :standard) click to toggle source
# 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