money-converter 0.1.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +50 -0
- data/VERSION +1 -1
- data/lib/base.rb +19 -0
- data/lib/money_converter.rb +18 -0
- data/money-converter.gemspec +5 -4
- metadata +6 -5
- data/README.rdoc +0 -19
- data/lib/money-converter.rb +0 -36
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# money-converter
|
2
|
+
|
3
|
+
### Download and Install
|
4
|
+
```
|
5
|
+
gem install money-converter
|
6
|
+
```
|
7
|
+
|
8
|
+
or on your Gemfile:
|
9
|
+
```
|
10
|
+
gem "money-converter", "~> 1.0.0"
|
11
|
+
```
|
12
|
+
|
13
|
+
and run
|
14
|
+
```
|
15
|
+
bundle install
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
### Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
|
24
|
+
require 'money_converter'
|
25
|
+
|
26
|
+
money = MoneyConverter.new('BRL','USD',10.00)
|
27
|
+
money.exchange #=> 4.74113
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
### Changelog
|
32
|
+
|
33
|
+
Version 1.0.0
|
34
|
+
|
35
|
+
* The method ``` convert_currency ``` has been replaced by ``` exchange ``` in this version.
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
### Contributing to money-converter
|
41
|
+
|
42
|
+
1. Fork the project.
|
43
|
+
2. Start a feature/bugfix branch.
|
44
|
+
3. Commit and push until you are happy with your contribution.
|
45
|
+
4. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
46
|
+
|
47
|
+
|
48
|
+
Copyright (c) 2012 LEONEL MORAIS. See LICENSE.txt for
|
49
|
+
further details.
|
50
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1
|
1
|
+
1.0.1
|
data/lib/base.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Base
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
def api_request(amount, from_currency, to_currency)
|
6
|
+
http = Net::HTTP.new("www.google.com",80)
|
7
|
+
resp = http.get("/ig/calculator?hl=en&q=#{amount}#{from_currency}=?#{to_currency}")
|
8
|
+
data = resp.body
|
9
|
+
format_amount_exchanged(data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def format_amount_exchanged(data)
|
13
|
+
array = data.split('"')
|
14
|
+
amount_exchanged = array[3].split
|
15
|
+
result = amount_exchanged[0].gsub(/[\xA0]/n, '')
|
16
|
+
"#{result} #{@to_currency}".to_f
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/http'
|
3
|
+
require 'base'
|
4
|
+
|
5
|
+
class MoneyConverter
|
6
|
+
include Base
|
7
|
+
|
8
|
+
def initialize(from_currency, to_currency, amount)
|
9
|
+
@from_currency = from_currency
|
10
|
+
@to_currency = to_currency
|
11
|
+
@amount = amount
|
12
|
+
end
|
13
|
+
|
14
|
+
def exchange
|
15
|
+
api_request(@amount, @from_currency, @to_currency)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/money-converter.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "money-converter"
|
8
|
-
s.version = "0.1
|
8
|
+
s.version = "1.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["LEONEL MORAIS"]
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.email = "leonel.morais@yahoo.com.br"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
@@ -22,10 +22,11 @@ Gem::Specification.new do |s|
|
|
22
22
|
"Gemfile",
|
23
23
|
"Gemfile.lock",
|
24
24
|
"LICENSE.txt",
|
25
|
-
"README.
|
25
|
+
"README.md",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
|
-
"lib/
|
28
|
+
"lib/base.rb",
|
29
|
+
"lib/money_converter.rb",
|
29
30
|
"money-converter.gemspec",
|
30
31
|
"spec/money-converter_spec.rb",
|
31
32
|
"spec/spec_helper.rb"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -97,17 +97,18 @@ executables: []
|
|
97
97
|
extensions: []
|
98
98
|
extra_rdoc_files:
|
99
99
|
- LICENSE.txt
|
100
|
-
- README.
|
100
|
+
- README.md
|
101
101
|
files:
|
102
102
|
- .document
|
103
103
|
- .rspec
|
104
104
|
- Gemfile
|
105
105
|
- Gemfile.lock
|
106
106
|
- LICENSE.txt
|
107
|
-
- README.
|
107
|
+
- README.md
|
108
108
|
- Rakefile
|
109
109
|
- VERSION
|
110
|
-
- lib/
|
110
|
+
- lib/base.rb
|
111
|
+
- lib/money_converter.rb
|
111
112
|
- money-converter.gemspec
|
112
113
|
- spec/money-converter_spec.rb
|
113
114
|
- spec/spec_helper.rb
|
@@ -126,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
127
|
version: '0'
|
127
128
|
segments:
|
128
129
|
- 0
|
129
|
-
hash:
|
130
|
+
hash: 43933295
|
130
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
132
|
none: false
|
132
133
|
requirements:
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= money-converter
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to money-converter
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
-
* Fork the project.
|
10
|
-
* Start a feature/bugfix branch.
|
11
|
-
* Commit and push until you are happy with your contribution.
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2012 LEONEL MORAIS. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|
data/lib/money-converter.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'net/http'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
|
6
|
-
class MoneyConverter
|
7
|
-
|
8
|
-
def initialize(from_currency, to_currency, amount)
|
9
|
-
@from_currency = from_currency
|
10
|
-
@to_currency = to_currency
|
11
|
-
@amount = amount
|
12
|
-
end
|
13
|
-
|
14
|
-
def convert_currency
|
15
|
-
api_request(@amount, @from_currency, @to_currency)
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def api_request(amount, from_currency, to_currency)
|
22
|
-
http = Net::HTTP.new("www.google.com",80)
|
23
|
-
resp = http.get("/ig/calculator?hl=en&q=#{amount}#{from_currency}=?#{to_currency}")
|
24
|
-
data = resp.body
|
25
|
-
format_amount_exchanged(data, to_currency)
|
26
|
-
#result = JSON(r.gsub(/([\w]+):/, '"\1":'))
|
27
|
-
end
|
28
|
-
|
29
|
-
def format_amount_exchanged(data, to_currency)
|
30
|
-
array = data.split('"')
|
31
|
-
amount_exchanged = array[3].split
|
32
|
-
result = amount_exchanged[0].gsub(/[\xA0]/n, '')
|
33
|
-
"#{result} #{to_currency}".to_sym
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|