convers_money 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69c34b7aae24a455b862d3f22e03836a79a3fa45
4
- data.tar.gz: 18b2f788e8c2ee46a50b7f0490455bbd86257f9e
3
+ metadata.gz: e550192aacf950e861c7051c8341dd915412ce02
4
+ data.tar.gz: 1db1f09cfdff2c3b34225bd3d5cd89fa735abb23
5
5
  SHA512:
6
- metadata.gz: ebed51488bfad055db104033f03c7f14cbada3acaef865300a324e97549da679c44369586087927b8caa6e3a9ab4b13adb21fd9fbc6703f6a7d89bce62356586
7
- data.tar.gz: 790f608ac5bf1a2eb577a4fd2e7990232c92471ea143eb9822689de4ede05b7cf5f45130a778d919e9de0681f77e78cf2e38844f8d9f32738a3926f6bb9f9182
6
+ metadata.gz: dd519d7aa9f932620e369b7684e854fb9f2ef60d824278969f68231182ecb8c255ce93923a426c446eddd0f63600a0fab5fec9a542a410aeefc3d85d41b27866
7
+ data.tar.gz: fea2c1b35cad3d7511af1a2f6be016ab7d773f1d9e7796ca5419b209bf112eb26800cd95b73d6e761afd40db4e8a08463c4f2ede87063b9eeac2663a09f784b7
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['antonelo@gmail.com']
11
11
 
12
12
  spec.summary = 'Money conversor'
13
- spec.description = "ConversMoney it's a Money Conversor given by fixed currency and change rates of your choice. \n This version '1.0.0' it's the first full working version"
13
+ spec.description = "ConversMoney it's a Money Conversor given by fixed currency and change rates of your choice. \r\n From the version and further '1.0.1' it's a full working version"
14
14
  spec.homepage = 'https://github.com/nelantone/convers_money'
15
15
  spec.license = 'MIT'
16
16
 
@@ -56,58 +56,77 @@ class ConversMoney
56
56
  "#{format('%.2f', @amount)} #{@currency}"
57
57
  end
58
58
 
59
- def convert_float_to_instance(other, currency)
60
- if other.is_a? Float
61
- other = ConversMoney.new( other, currency)
59
+ def convert_to_reference_currency(other, currency)
60
+ if (other.is_a? Float ) || (other.is_a? Integer)
61
+ ConversMoney.new( other, currency)
62
+ else
63
+ other.convert_to(currency)
62
64
  end
63
65
  end
64
66
 
67
+ # def resut_conversion(other, currency, total_amount)
68
+ # result = ConversMoney.new(total_amount.round(2), currency)
69
+ # if other.amount.is_a? Integer
70
+ # result.amount = result.amount.to_i
71
+ # result
72
+ # end
73
+ # end
74
+
65
75
  def +(other)
66
- if other.is_a? Float
67
- other = ConversMoney.new( other, currency)
76
+ other = convert_to_reference_currency(other, currency)
77
+ total_amount = amount + other.amount
78
+ result = ConversMoney.new(total_amount.round(2), currency)
79
+ if other.amount.is_a? Integer
80
+ result.amount = result.amount.to_i
81
+ result
82
+ else
83
+ result
68
84
  end
69
- total_amount = amount + other.convert_to(currency).amount
70
- ConversMoney.new(total_amount.to_f.round(2), currency)
71
85
  end
72
86
 
73
87
  def -(other)
74
- if other.is_a? Float
75
- other = ConversMoney.new( other, currency)
88
+ other = convert_to_reference_currency(other, currency)
89
+ total_amount = amount - other.amount
90
+ result = ConversMoney.new(total_amount.round(2), currency)
91
+ if other.amount.is_a? Integer
92
+ result.amount = result.amount.to_i
93
+ result
94
+ else
95
+ result
76
96
  end
77
- total_amount = amount - other.convert_to(currency).amount
78
- ConversMoney.new(total_amount.to_f.round(2), currency)
79
97
  end
80
98
 
81
99
  def *(other)
82
- if other.is_a? Float
83
- other = ConversMoney.new( other, currency)
100
+ other = convert_to_reference_currency(other, currency)
101
+ total_amount = amount * other.amount
102
+ result = ConversMoney.new(total_amount.round(2), currency)
103
+ if other.amount.is_a? Integer
104
+ result.amount = result.amount.to_i
105
+ result
106
+ else
107
+ result
84
108
  end
85
- total_amount = amount * other.convert_to(currency).amount
86
- ConversMoney.new(total_amount.to_f.round(2), currency)
87
109
  end
88
110
 
89
111
  def /(other)
90
- if other.is_a? Float
91
- other = ConversMoney.new( other, currency)
112
+ other = convert_to_reference_currency(other, currency)
113
+ total_amount = amount / other.amount
114
+ result = ConversMoney.new(total_amount.round(2), currency)
115
+ if other.amount.is_a? Integer
116
+ result.amount = result.amount.to_i
117
+ result
118
+ else
119
+ result
92
120
  end
93
- total_amount = amount / other.convert_to(currency).amount
94
- ConversMoney.new(total_amount.to_f.round(2), currency)
95
121
  end
96
122
 
97
123
  def <=>(other)
98
124
  if other.is_a? Float
99
125
  other = ConversMoney.new( other.round(2), currency)
100
- end
101
- amount.round(2) <=> other.convert_to(currency).amount.round(2)
102
- end
103
-
104
- def self.checking_fixed_currency(other, currency)
105
- if other.currency.eql?(currency)
106
- other
107
126
  else
108
- conversion_rates_access
109
- other.convert_to(currency)
127
+ other = convert_to_reference_currency(other, currency)
110
128
  end
129
+ amount.round(2) <=> other.amount.round(2)
111
130
  end
112
131
 
113
132
  def self.conversion_rates_access
@@ -1,3 +1,3 @@
1
1
  class ConversMoney
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: convers_money
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toño Serna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-12 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,7 +99,8 @@ dependencies:
99
99
  - !ruby/object:Gem::Version
100
100
  version: 4.6.0
101
101
  description: "ConversMoney it's a Money Conversor given by fixed currency and change
102
- rates of your choice. \n This version '1.0.0' it's the first full working version"
102
+ rates of your choice. \r\n From the version and further '1.0.1' it's a full working
103
+ version"
103
104
  email:
104
105
  - antonelo@gmail.com
105
106
  executables: []