-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Karthikeyan A K
committed
Nov 7, 2012
1 parent
bf40e76
commit 5d11abe
Showing
4 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'net/http' | ||
|
||
# Converts currency from one format to another, for example from USD to | ||
# EUR | ||
# from_curr the code for the currency that needs to be converted | ||
# to_curr the code for the currency that needs to be converted to | ||
# amount amount of money in from_curr | ||
def convert_currency(from_curr = "INR", to_curr = "USD", amount = 1000) | ||
host = "www.google.com" | ||
http = Net::HTTP.new(host, 80) | ||
url = "/finance/converter?a=#{amount}&from=#{from_curr}&to=#{to_curr}" | ||
response = http.get(url) | ||
# puts response.body | ||
result = response.body | ||
regexp = Regexp.new("(\\d+\\.{0,1}\\d*)\\s+#{to_curr}") | ||
regexp.match result | ||
return $1.to_f | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Gem::Specification.new do |s| | ||
s.name = 'money-mind' | ||
s.version = '0.0.0' | ||
s.date = '2012-11-05' | ||
s.summary = "Money Mind" | ||
s.description = "A simple currency conversion code in Ruby" | ||
s.authors = ["Karthikeyan A K"] | ||
s.email = '[email protected]' | ||
s.files = ["lib/money-mind.rb"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require '../lib/money-mind.rb' | ||
|
||
puts convert_currency("USD", "EUR", 1000) |