currency_converter 0.0.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.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
@@ -0,0 +1 @@
1
+ == 0.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in currency.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Diganta Mandal
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # CurrencyConverter
2
+
3
+ Google provides a web site to converts currencies using exchange rates but they have not provided any API for ruby. This is a small library that converts currencies exchange rate. You can convert currencies directly through this library.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'currency_converter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install currency_converter
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'currency_converter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "currency_converter"
8
+ spec.version = CurrencyConverter::VERSION.dup
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.license = "MIT"
11
+
12
+ spec.authors = ["Diganta Mandal"]
13
+ spec.email = ["diganta@circarconsulting.com"]
14
+ spec.description = %q{Google provides a web site to converts currencies using exchange rates but they have not provided any API for ruby. This is a small library that converts currencies exchange rate. You can convert currencies directly through this library.}
15
+ spec.summary = %q{Google provides a web site to converts currencies using exchange rates but they have not provided any API for ruby. This is a small library that converts currencies exchange rate. You can convert currencies directly through this library.}
16
+ spec.homepage = "https://github.com/diganta/currency"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.required_ruby_version = ">= 1.8.7"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec", "~> 2.14"
28
+ spec.add_development_dependency "yard", "~> 0.8"
29
+ spec.add_development_dependency "kramdown", "~> 1.1"
30
+ end
@@ -0,0 +1,54 @@
1
+ require "currency_converter/currencies"
2
+ require "currency_converter/version"
3
+ require "net/http"
4
+
5
+ module CurrencyConverter
6
+ class << self
7
+ # Returns the Symbol of 'from' currency
8
+ attr_reader :from_currency
9
+
10
+ # Returns the Symbol of 'to' currency
11
+ attr_reader :to_currency
12
+
13
+ # Receive the amount of you desire currency.
14
+ #
15
+ # @param [String, String, Numeric] other currency to exchange to.
16
+ #
17
+ # @return [amount]
18
+ #
19
+ # @example
20
+ # CurrencyConverter.exchange("USD", "EUR", 100)
21
+ # CurrencyConverter.exchange("USD", "INR", 100)
22
+ def exchange(from, to, fixnum)
23
+ @from_currency = from.upcase.to_sym
24
+ @to_currency = to.upcase.to_sym
25
+ raise StandardError, "Currency #{from_currency} or #{to_currency} is invalid" unless valid_currency?
26
+ ex_rate = exchange_rate
27
+ raise StandardError, "Can't find any exchange rate" if ex_rate.nil?
28
+ value = "%.2f" % (ex_rate.to_f * fixnum).to_s
29
+ value.to_f
30
+ end
31
+
32
+ private
33
+
34
+ # Returns the Float value of rate or nil
35
+ def exchange_rate
36
+ http = Net::HTTP.new("www.google.com", 80)
37
+ url = "/finance/converter?a=1&from=#{from_currency.to_s.upcase}&to=#{to_currency.to_s.upcase}"
38
+ response = http.get(url)
39
+ result = response.body
40
+ regexp = Regexp.new("(\\d+\\.{0,1}\\d*)\\s+#{to_currency}")
41
+ regexp.match result
42
+ return $1
43
+ rescue Timeout::Error
44
+ raise StandardError, "Please check your internet connection"
45
+ end
46
+
47
+ # Check if currency is valid
48
+ #
49
+ # Returns true if currency is valid
50
+ def valid_currency?
51
+ CurrencyConverter::CURRENCIES.has_key?(from_currency) && CurrencyConverter::CURRENCIES.has_key?(to_currency)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,99 @@
1
+ # coding: utf-8
2
+ module CurrencyConverter
3
+ CURRENCIES = {
4
+ :AED => "United Arab Emirates Dirham",
5
+ :ANG => "Netherlands Antillean Guilder",
6
+ :ARS => "Argentine Peso",
7
+ :AUD => "Australian Dollar",
8
+ :BDT => "Bangladeshi Taka",
9
+ :BGN => "Bulgarian Lev",
10
+ :BHD => "Bahraini Dinar",
11
+ :BND => "Brunei Dollar",
12
+ :BOB => "Bolivian Boliviano",
13
+ :BRL => "Brazilian Real",
14
+ :BWP => "Botswanan Pula",
15
+ :CAD => "Canadian Dollar",
16
+ :CHF => "Swiss Franc",
17
+ :CLP => "Chilean Peso",
18
+ :CNY => "Chinese Yuan",
19
+ :COP => "Colombian Peso",
20
+ :CRC => "Costa Rican Colón",
21
+ :CZK => "Czech Republic Koruna",
22
+ :DKK => "Danish Krone",
23
+ :DOP => "Dominican Peso",
24
+ :DZD => "Algerian Dinar",
25
+ :EEK => "Estonian Kroon",
26
+ :EGP => "Egyptian Pound",
27
+ :EUR => "Euro",
28
+ :FJD => "Fijian Dollar",
29
+ :GBP => "British Pound Sterling",
30
+ :HKD => "Hong Kong Dollar",
31
+ :HNL => "Honduran Lempira",
32
+ :HRK => "Croatian Kuna",
33
+ :HUF => "Hungarian Forint",
34
+ :IDR => "Indonesian Rupiah",
35
+ :ILS => "Israeli New Sheqel",
36
+ :INR => "Indian Rupee",
37
+ :JMD => "Jamaican Dollar",
38
+ :JOD => "Jordanian Dinar",
39
+ :JPY => "Japanese Yen",
40
+ :KES => "Kenyan Shilling",
41
+ :KRW => "South Korean Won",
42
+ :KWD => "Kuwaiti Dinar",
43
+ :KYD => "Cayman Islands Dollar",
44
+ :KZT => "Kazakhstani Tenge",
45
+ :LBP => "Lebanese Pound",
46
+ :LKR => "Sri Lankan Rupee",
47
+ :LTL => "Lithuanian Litas",
48
+ :LVL => "Latvian Lats",
49
+ :MAD => "Moroccan Dirham",
50
+ :MDL => "Moldovan Leu",
51
+ :MKD => "Macedonian Denar",
52
+ :MUR => "Mauritian Rupee",
53
+ :MVR => "Maldivian Rufiyaa",
54
+ :MXN => "Mexican Peso",
55
+ :MYR => "Malaysian Ringgit",
56
+ :NAD => "Namibian Dollar",
57
+ :NGN => "Nigerian Naira",
58
+ :NIO => "Nicaraguan Córdoba",
59
+ :NOK => "Norwegian Krone",
60
+ :NPR => "Nepalese Rupee",
61
+ :NZD => "New Zealand Dollar",
62
+ :OMR => "Omani Rial",
63
+ :PEN => "Peruvian Nuevo Sol",
64
+ :PGK => "Papua New Guinean Kina",
65
+ :PHP => "Philippine Peso",
66
+ :PKR => "Pakistani Rupee",
67
+ :PLN => "Polish Zloty",
68
+ :PYG => "Paraguayan Guarani",
69
+ :QAR => "Qatari Rial",
70
+ :RON => "Romanian Leu",
71
+ :RSD => "Serbian Dinar",
72
+ :RUB => "Russian Ruble",
73
+ :SAR => "Saudi Riyal",
74
+ :SCR => "Seychellois Rupee",
75
+ :SEK => "Swedish Krona",
76
+ :SGD => "Singapore Dollar",
77
+ :SKK => "Slovak Koruna",
78
+ :SLL => "Sierra Leonean Leone",
79
+ :SVC => "Salvadoran Colón",
80
+ :THB => "Thai Baht",
81
+ :TND => "Tunisian Dinar",
82
+ :TRY => "Turkish Lira",
83
+ :TTD => "Trinidad and Tobago Dollar",
84
+ :TWD => "New Taiwan Dollar",
85
+ :TZS => "Tanzanian Shilling",
86
+ :UAH => "Ukrainian Hryvnia",
87
+ :UGX => "Ugandan Shilling",
88
+ :USD => "US Dollar",
89
+ :UYU => "Uruguayan Peso",
90
+ :UZS => "Uzbekistan Som",
91
+ :VEF => "Venezuelan Bolívar",
92
+ :VND => "Vietnamese Dong",
93
+ :XOF => "CFA Franc BCEAO",
94
+ :YER => "Yemeni Rial",
95
+ :ZAR => "South African Rand",
96
+ :ZMK => "Zambian Kwacha (1968-2012)",
97
+ :ZMW => "Zambian Kwacha"
98
+ }.freeze
99
+ end
@@ -0,0 +1,3 @@
1
+ module CurrencyConverter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe CurrencyConverter do
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'rspec'
3
+ require 'currency_converter'
4
+
5
+ RSpec.configure do |config|
6
+ config.order = "rand"
7
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: currency_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Diganta Mandal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &83669940 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *83669940
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &83669730 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *83669730
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &83669450 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.14'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *83669450
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ requirement: &83669200 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *83669200
58
+ - !ruby/object:Gem::Dependency
59
+ name: kramdown
60
+ requirement: &83668970 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '1.1'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *83668970
69
+ description: Google provides a web site to converts currencies using exchange rates
70
+ but they have not provided any API for ruby. This is a small library that converts
71
+ currencies exchange rate. You can convert currencies directly through this library.
72
+ email:
73
+ - diganta@circarconsulting.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - currency_converter.gemspec
85
+ - lib/currency_converter.rb
86
+ - lib/currency_converter/currencies.rb
87
+ - lib/currency_converter/version.rb
88
+ - spec/currency_converter_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/diganta/currency
91
+ licenses:
92
+ - MIT
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: 1.8.7
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 1.8.17
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Google provides a web site to converts currencies using exchange rates but
115
+ they have not provided any API for ruby. This is a small library that converts currencies
116
+ exchange rate. You can convert currencies directly through this library.
117
+ test_files:
118
+ - spec/currency_converter_spec.rb
119
+ - spec/spec_helper.rb