class Indices
Public Class Methods
new(agent, auth, *params)
click to toggle source
# File lib/finviz_rails/indices.rb, line 2 def initialize(agent, auth, *params) @agent = agent @auth = auth @results = {} end
Public Instance Methods
run()
click to toggle source
# File lib/finviz_rails/indices.rb, line 8 def run @agent.get(url) matches.map do |match| indice = get_indice(match.first) percent_change = get_percent(match.first) @results[indice] = percent_change end @results end
Private Instance Methods
get_indice(string)
click to toggle source
# File lib/finviz_rails/indices.rb, line 20 def get_indice(string) string.match(/^"(.+?)"/)[1] end
get_percent(string)
click to toggle source
# File lib/finviz_rails/indices.rb, line 24 def get_percent(string) string.match(/change":(\d*\.?\d*)/)[1].to_f end
matches()
click to toggle source
# File lib/finviz_rails/indices.rb, line 32 def matches @agent.page.content.scan /{"label":(.+?),"sparkline"/ end
url()
click to toggle source
# File lib/finviz_rails/indices.rb, line 28 def url "http://#{'elite.' if @auth}finviz.com/futures_charts.ashx?t=INDICES&p=d1" end