rents 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rents/currency.rb +10 -1
- data/lib/rents/string.rb +4 -0
- data/lib/rents/version.rb +1 -1
- data/spec/helpers.rb +5 -3
- data/spec/rents/currency_spec.rb +18 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c22cc7b5b9ba3becc4f26e2cfe578fe28b3a1c2
|
4
|
+
data.tar.gz: a8481c0c25b891e34a5523a608e0ad7d0b891424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a876a9c4ab0c915ebe9e62d1ebedc7e4c3446dd0900394d32cae22f5d89d799523249c5185f8057194a9d1535bfcf637ae5f6ac641d3775b9049d944a9661df
|
7
|
+
data.tar.gz: 7bc2234cc3f8f1ef1fa253565d195a4d43661842fc2218c283e8c93406676bab3b792dab3d514b97ae4edd2c97d9d6793af6119a034caac539fe19a05c8adaea
|
data/lib/rents/currency.rb
CHANGED
@@ -6,7 +6,16 @@ module Rents
|
|
6
6
|
# Check invalid entry
|
7
7
|
return nil if amount.nil?
|
8
8
|
return amount.to_s if amount.is_a?Integer
|
9
|
-
|
9
|
+
amount = format('%.2f', amount) if amount.to_s.float?
|
10
|
+
|
11
|
+
if amount.is_a?String
|
12
|
+
return amount if amount.index('.').nil? && amount.index(',').nil?
|
13
|
+
|
14
|
+
amount = amount.remove('.')
|
15
|
+
amount = amount.remove(',')
|
16
|
+
|
17
|
+
return amount
|
18
|
+
end
|
10
19
|
|
11
20
|
# Convert from BigDecimal
|
12
21
|
if amount.is_a?BigDecimal
|
data/lib/rents/string.rb
CHANGED
data/lib/rents/version.rb
CHANGED
data/spec/helpers.rb
CHANGED
@@ -20,14 +20,16 @@ module Helpers
|
|
20
20
|
until count == items_amount do
|
21
21
|
count = count+1
|
22
22
|
rand_count_departments = Random.new.rand(1..10)
|
23
|
-
|
23
|
+
sold_item = {
|
24
24
|
remote_id: Faker::Number.number(count),
|
25
25
|
name: Faker::Commerce.product_name,
|
26
26
|
description: Faker::Commerce.department(rand_count_departments, rand_count_departments==2)
|
27
|
-
}
|
27
|
+
}
|
28
|
+
|
29
|
+
sold_items << sold_item
|
28
30
|
end
|
29
31
|
|
30
|
-
|
32
|
+
sold_items
|
31
33
|
end
|
32
34
|
|
33
35
|
def get_json url
|
data/spec/rents/currency_spec.rb
CHANGED
@@ -17,11 +17,15 @@ describe Rents::Currency do
|
|
17
17
|
decimal_value = BigDecimal.new '1999.00'
|
18
18
|
operator_with_cents = '300055' # R$ 3.000,55
|
19
19
|
decimal_expected_value = BigDecimal.new '1999.00'
|
20
|
-
|
20
|
+
expected_float_unit_cents = '100005'
|
21
|
+
expected_float_decimal_cents = '100050'
|
21
22
|
|
22
23
|
# Float values
|
23
24
|
float_with_cents = 1000.55
|
24
|
-
float_without_cents = 1000.
|
25
|
+
float_without_cents = 1000.00
|
26
|
+
|
27
|
+
float_unit_cents = 1000.05
|
28
|
+
float_decimal_cents = 1000.50
|
25
29
|
|
26
30
|
# Values Converted to operator format
|
27
31
|
non_cents_received = Rents::Currency.get_cents operator_value
|
@@ -33,6 +37,8 @@ describe Rents::Currency do
|
|
33
37
|
big_decimal_converted = Rents::Currency.to_operator_str decimal_value
|
34
38
|
non_formatted_converted = Rents::Currency.to_operator_str non_formatted
|
35
39
|
non_formatted_with_cents_converted = Rents::Currency.to_operator_str non_formatted_with_cents
|
40
|
+
float_unit_cents_conv = Rents::Currency.to_operator_str float_unit_cents
|
41
|
+
float_decimal_cents_conv = Rents::Currency.to_operator_str float_decimal_cents
|
36
42
|
|
37
43
|
context 'Decimal to Operator' do
|
38
44
|
# Convert PT_BR
|
@@ -73,6 +79,16 @@ describe Rents::Currency do
|
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
82
|
+
context 'Float to Operator' do
|
83
|
+
it 'unit cents con must be on Operator format' do
|
84
|
+
expect(float_unit_cents_conv).to be == expected_float_unit_cents
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'decimal cents con must be on Operator format' do
|
88
|
+
expect(float_decimal_cents_conv).to be == expected_float_decimal_cents
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
76
92
|
context 'Operator to Decimal' do
|
77
93
|
# Convert from the operator to BigDecimal instance, like rails does/need
|
78
94
|
it 'should be the BigDecimal expected' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rents
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilton Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|