yahoofx 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +8 -0
- data/lib/yahoofx/converter.rb +6 -6
- data/test/unit/converter_test.rb +4 -0
- data/yahoofx.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -17,6 +17,14 @@ E.g. `yahoofx eurusd` outputs 1.2925 if the price of 1 EUR is 1.2925 USD
|
|
17
17
|
|
18
18
|
To use this in your ruby code, this would return the rate as a Float: `Yahoofx::Pair.new(:eur, :usd).bid`
|
19
19
|
|
20
|
+
#### Convert amounts to other currencies
|
21
|
+
|
22
|
+
Can also convert an amount of money from one currency to the other:
|
23
|
+
`Yahoofx::Converter.new.answer("100 EUR in USD")`
|
24
|
+
|
25
|
+
Or use the shell command:
|
26
|
+
`yahoofx [amount] [from currency] in [to currency]` e.g. `yahoofx 100 EUR in USD`
|
27
|
+
|
20
28
|
## License
|
21
29
|
|
22
30
|
The MIT License (MIT)
|
data/lib/yahoofx/converter.rb
CHANGED
@@ -20,12 +20,12 @@ module Yahoofx
|
|
20
20
|
@rate_class.new(parsed[:from_currency], parsed[:to_currency]).bid*parsed[:from_amount]
|
21
21
|
end
|
22
22
|
|
23
|
-
# Example parameter: 100 EUR in USD
|
24
|
-
def parse(input_string)
|
25
|
-
|
26
|
-
{ :from_amount =>
|
27
|
-
:from_currency =>
|
28
|
-
:to_currency =>
|
23
|
+
# Example parameter: "100 EUR in USD"
|
24
|
+
def parse(input_string)
|
25
|
+
/([\d]+)[\p{Space}]*(.*)in(.*)/ =~ input_string
|
26
|
+
{ :from_amount => $1.to_f,
|
27
|
+
:from_currency => $2.strip,
|
28
|
+
:to_currency => $3.strip }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/test/unit/converter_test.rb
CHANGED
@@ -18,6 +18,10 @@ describe Yahoofx::Converter do
|
|
18
18
|
assert_equal 745.56, @converter.answer("100 EUR in DKK").to_f
|
19
19
|
end
|
20
20
|
|
21
|
+
it "should work the same without space between amount and 'from currency'" do
|
22
|
+
assert_equal 745.56, @converter.answer("100EUR in DKK").to_f
|
23
|
+
end
|
24
|
+
|
21
25
|
it "should show currency rate when two valid currency codes are provided" do
|
22
26
|
assert_equal 7.4556, @converter.answer("EURDKK").to_f
|
23
27
|
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.1.
|
3
|
+
s.version = '0.1.1'
|
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.1.
|
4
|
+
version: 0.1.1
|
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-
|
12
|
+
date: 2012-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: webmock
|