Skip to content

Commit

Permalink
added money-mind
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthikeyan A K committed Nov 7, 2012
1 parent bf40e76 commit 5d11abe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions money-mind/lib/money-mind.rb
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 added money-mind/money-mind-0.0.0.gem
Binary file not shown.
10 changes: 10 additions & 0 deletions money-mind/money-mind.gemspec
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
3 changes: 3 additions & 0 deletions money-mind/test/currency_test.rb
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)

0 comments on commit 5d11abe

Please sign in to comment.