Sha256: cddac0399697a06774eef9455c16e779275c9c4d25cd679bbae042af7bc1c923
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
require 'httpclient' require 'nokogiri' class Bovespa VERSION = "1.0.2" class Stock attr_accessor :code, :name, :date, :opening_price, :min_price, :max_price, :average_price, :last_price, :variation def to_s "#{@code} - '#{@name}' #{@opening_price} #{@min_price} #{@max_price} #{@average_price} #{@last_price} #{@variation}" end end def get *stock_codes result = Hash.new xml = Nokogiri.XML(HTTPClient.new.get_content("http://www.bmfbovespa.com.br/Pregao-Online/ExecutaAcaoAjax.asp?intEstado=1&CodigoPapel=#{URI.escape(stock_codes.join('|'))}")) xml.search('Papel').each do |p| st = Stock.new st.name = p['Nome'] st.date = p['Data'] st.opening_price = p['Abertura'].gsub(',','.').to_f st.min_price = p['Minimo'].gsub(',','.').to_f st.max_price = p['Maximo'].gsub(',','.').to_f st.average_price = p['Medio'].gsub(',','.').to_f st.last_price = p['Ultimo'].gsub(',','.').to_f st.variation = p['Oscilacao'].gsub(',','.').to_f st.code = p['Codigo'] result[st.code.to_sym] = st end return (stock_codes.size > 1 ? result : result[stock_codes.first]) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bovespa-prices-1.0.2 | lib/bovespa-prices.rb |