Class: IksScrape::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/iks_scrape.rb

Constant Summary collapse

HTTP_ENDPOINT =
'http://www.iks-kb.cz/web/fondy_denni_hodnoty.html'

Instance Method Summary collapse

Instance Method Details

#scrapeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/iks_scrape.rb', line 11

def scrape
	agent = Mechanize.new
	page = agent.get(HTTP_ENDPOINT)

	page.search("div#fundView tr").map do |tr|
		contents = tr.search("td").map(&:content).map(&:strip)
		next unless contents.size >= 3

		d = Date.parse(contents[1])

		stripped = contents[3].gsub(',','.').gsub(/[ ]/,'')
		price = stripped.to_f

		[
			contents[0],
			{ price: price, date: d }  # date: nil if unavailable
		]
	end.compact.to_h
end