Module: Fxkeb

Defined in:
lib/fxkeb.rb,
lib/fxkeb/version.rb

Constant Summary collapse

FXURL =
"http://community.fxkeb.com/fxportal/jsp/RS/DEPLOY_EXRATE/2533_0.html"
FIXED_RATE =
1000
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.to_usd(krw) ⇒ Object



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

def self.to_usd(krw)
  begin
    s = Net::HTTP.get('community.fxkeb.com', '/fxportal/jsp/RS/DEPLOY_EXRATE/2533_0.html')
    s = s.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "")
    doc = Nokogiri::HTML(s)#.force_encoding('ASCII-8BIT'))#, nil, 'EUC-KR')
    s = doc.css("td.text01")[5].content.to_s
    s = s[1..-1]
    unless s.length==7
      puts "!!!!!!! ERROR !!!!!!! s=>[#{s}]"
    end

    puts "fx => [#{s}]"
    puts "fx => [#{s.to_f}]"

    #doc = Nokogiri::HTML(open(FXURL))
    #return doc.css("td").first
    return (krw*10/s.to_f).ceil.to_f/10
    #return krw/1000
  rescue
    return krw/FIXED_RATE
  end
end