class Reality::Extras::Quandl::Economy

Public Class Methods

new(country) click to toggle source
# File lib/reality/extras/quandl.rb, line 7
def initialize(country)
  @country = country
end

Public Instance Methods

gdp() click to toggle source
# File lib/reality/extras/quandl.rb, line 11
def gdp
  gdp = fetch("ODA/#{@country.iso3_code}_NGDPD")
  gdp = gdp.to_i * 1_000_000_000
  Reality::Measure(gdp, '$')
end
inflation() click to toggle source
# File lib/reality/extras/quandl.rb, line 17
def inflation
  inflation = fetch("ODA/#{@country.iso3_code}_PCPIPCH")
  Reality::Measure(inflation, '%')
end
inspect() click to toggle source
# File lib/reality/extras/quandl.rb, line 27
def inspect
  "#<Reality::Quandl::Economy (%s)>" % [@country.name]
end
unemployment() click to toggle source
# File lib/reality/extras/quandl.rb, line 22
def unemployment
  unemployment = fetch("ODA/#{@country.iso3_code}_LUR")
  Reality::Measure(unemployment, '%')
end

Private Instance Methods

fetch(code) click to toggle source
# File lib/reality/extras/quandl.rb, line 33
def fetch(code)
  ::Quandl::ApiConfig.api_key ||= Reality.config.fetch('keys', 'quandl')
  database, dataset = code.split('/')
  data = ::Quandl::Data.all({ params: { database_code: database, dataset_code: dataset }})
  data.values.select { |v| v['date'] <= Date.today }.sort_by { |d| d['date'] }.last.value
rescue ::Quandl::NotFoundError
  nil
end