class Indicadores::Chile

Constants

SERVICE_URL

Attributes

srv_response[RW]

Public Class Methods

new() click to toggle source
# File lib/indicadores_cl.rb, line 11
def initialize
  @srv_response = fetch
end

Private Class Methods

format(str) click to toggle source
# File lib/indicadores_cl.rb, line 56
def self.format(str)
  str.gsub('$','').gsub('.','').gsub(',','.').to_f
end

Public Instance Methods

dolar() click to toggle source
# File lib/indicadores_cl.rb, line 27
def dolar
  get_moneda_value "dolar"
end
euro() click to toggle source
# File lib/indicadores_cl.rb, line 31
def euro
  get_moneda_value "euro"
end
get_indicador_value(indicador) click to toggle source
# File lib/indicadores_cl.rb, line 35
def get_indicador_value(indicador)
  return 0 if srv_response["indicador"].nil?
  srv_response["indicador"][0][indicador][0]["valor"].to_f
end
get_moneda_value(moneda) click to toggle source
# File lib/indicadores_cl.rb, line 40
def get_moneda_value(moneda)
  return 0 if srv_response["moneda"].nil?
  srv_response["moneda"][0][moneda][0]["valor"].to_f
end
ipc() click to toggle source
# File lib/indicadores_cl.rb, line 19
def ipc
  get_indicador_value "ipc"
end
uf() click to toggle source
# File lib/indicadores_cl.rb, line 15
def uf
  get_indicador_value "uf"
end
utm() click to toggle source
# File lib/indicadores_cl.rb, line 23
def utm
  get_indicador_value "utm"
end

Private Instance Methods

fetch() click to toggle source
# File lib/indicadores_cl.rb, line 47
def fetch
  begin
    srv_response ||= open(SERVICE_URL).read
    XmlSimple.xml_in(srv_response)
  rescue Exception => e
    nil
  end
end