Module: DolarHoy

Defined in:
lib/dolarhoy.rb

Defined Under Namespace

Classes: Currency

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.fetch(html = self.html) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dolarhoy.rb', line 8

def self.fetch(html = self.html)
  doc = Nokogiri::HTML(html)

  currencies = []

  doc.css("body > div table[@bgcolor='#000000']").each do |table|
    values = table.css("font[@size='3']")
    next unless values.size > 1

    currency = Currency.new(
      table.at_css("td:first").inner_text,
      values[0].inner_text,
      values[1].inner_text
    )

    currencies << currency
  end

  currencies
end

.htmlObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dolarhoy.rb', line 29

def self.html
  response = Net::HTTP.start(URI.parse('http://www.dolarhoy.com').host) do |http|
    http.get('/indexx.php', 'Referer' => 'http://www.dolarhoy.com')
  end

  if RUBY_VERSION > "1.9"
    response.body.force_encoding("ISO-8859-1").encode("UTF-8")
  else
    response.body
  end
end