Permalink
Browse files

Merge pull request #1 from timcase/master

add compability for ruby greater than or equal to 2.0
  • Loading branch information...
2 parents 2e83f39 + 2c0c02a commit 7a09e02f88a82ecd043697e8b51374e5bad40981 @scottjbarr committed May 13, 2014
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/yahoo_currency/yahoo_currency.rb
@@ -18,6 +18,8 @@ def self.get_rate!(from, to)
# hit the url
resp, data = http.get(target)
+ # ruby >= 2.0 compatibility
+ data = resp.body if RUBY_VERSION > "1.9"
# check the response code
if resp.code.to_i != 200
@@ -35,23 +37,23 @@ def self.get_rate!(from, to)
def self.parse_rate(data)
data.split(',')[1].to_f
end
-
+
#
# The timestamp is in the 2 and 3rd fields of the CSV
#
- # The timestamp in the data from Yahoo will in the format
+ # The timestamp in the data from Yahoo will in the format
# "M/D/YYYY HH:mm:ampm" Eg. 6/18/2008 2:45am
#
def self.parse_timestamp(data)
data = data.gsub('"', '')
d = data.chop.split(',')[2]
t = data.split(',')[3].gsub('"', '')
-
+
return nil if d == "N/A"
-
+
dp = d.split("/")
-
+
Time.parse("#{dp[2].to_i}/#{dp[0]}/#{dp[1].to_i} #{t}".chop)
end
-
+
end

0 comments on commit 7a09e02

Please sign in to comment.