yahoofx 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,3 +8,5 @@ Includes shell command that returns the rate. Usage: yahoofx
8
8
  [currency pair]
9
9
 
10
10
  E.g. `yahoofx eurusd` outputs 1.2925 if the price of 1 EUR is 1.2925 USD
11
+
12
+ To use this in your ruby code, this would return the rate as a Float: `Yahoofx::Pair.new(:eur, :usd).bid`
data/lib/yahoofx/pair.rb CHANGED
@@ -5,14 +5,21 @@ module Yahoofx
5
5
  # First and second currency code. The parameters could be "USD" and "EUR" for instance
6
6
  def initialize(first, second)
7
7
  @first, @second = first.to_s, second.to_s
8
- raise "Invalid currency code provided" unless @first.length==3 && @second.length==3
8
+ raise "Invalid currency code provided" unless valid_currency_code?(@first) &&
9
+ valid_currency_code?(@second)
9
10
  end
10
11
 
11
12
  def bid
12
13
  request_feed.scan(bid_regexp).each { |results| return results.first.to_f }
14
+ nil
13
15
  end
14
16
 
15
17
  protected
18
+ def valid_currency_code?(currency_code)
19
+ return true if currency_code =~ /^[a-zA-Z]{3}$/
20
+ false
21
+ end
22
+
16
23
  def url_for_currency_pair
17
24
  URI("http://finance.yahoo.com/q?s=#{@first}#{@second}%3Dx&ql=1")
18
25
  end
@@ -1,5 +1,4 @@
1
1
  require_relative "../test_helper"
2
- #p YahooFx::Pair.new(:eur, :usd).bid
3
2
 
4
3
  describe Yahoofx do
5
4
  before do
@@ -13,4 +12,10 @@ describe Yahoofx do
13
12
  assert_equal 1.2967, Yahoofx::Pair.new(:eur, :usd).bid
14
13
  end
15
14
 
15
+ describe "when providing a currency code that's not 3 letters" do
16
+ it "should raise an exception" do
17
+ proc {Yahoofx::Pair.new(:usd, :foooo)}.must_raise(RuntimeError)
18
+ proc {Yahoofx::Pair.new(:us1, :eur)}.must_raise(RuntimeError)
19
+ end
20
+ end
16
21
  end
data/yahoofx.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'yahoofx'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.executables << 'yahoofx'
5
5
  s.summary = "Gets currency rates from Yahoo Finance"
6
6
  s.description = "The gem scrapes Yahoo Finance and returns foreign exchange rates. Also comes with a shell command."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoofx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmock