6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/nasdaq_query/dividend_history.rb', line 6
def self.for_symbol(sym)
doc = Nokogiri::HTML(`curl -s 'http://www.nasdaq.com/symbol/#{sym.downcase}/dividend-history'`)
rows = doc.xpath("//table[@class='dataGrid']/tr")
rows.shift entries = rows.map do |row|
tds = row.xpath(".//td")
{
:ex_eff_date => begin; Date.strptime(tds[0].xpath(".//span").text, "%m/%d/%Y"); rescue; nil; end,
:type => tds[1].text,
:cash_amt => tds[2].xpath(".//span").text.to_f,
:declaration_date => begin; Date.strptime(tds[3].xpath(".//span").text, "%m/%d/%Y"); rescue; nil; end,
:record_date => begin; Date.strptime(tds[4].xpath(".//span").text, "%m/%d/%Y"); rescue; nil; end,
:payment_date => begin; Date.strptime(tds[5].xpath(".//span").text, "%m/%d/%Y"); rescue; nil; end
}
end
end
|