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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42b0dc630322ec2593c3995e81d3957d15deabaf
4
- data.tar.gz: 64997dc821487e18f5915e2cd8bf9a544a137079
3
+ metadata.gz: 0c22cc7b5b9ba3becc4f26e2cfe578fe28b3a1c2
4
+ data.tar.gz: a8481c0c25b891e34a5523a608e0ad7d0b891424
5
5
  SHA512:
6
- metadata.gz: 2e0316c3d8a317f719c186af01f5f7c759c5db0e371822d4a0bfd3e7b02b550cf0a7052347f51cdc72096bc029b04c5bd999514cd6206c8ed6337dc1f0117c64
7
- data.tar.gz: cbfe2b293ad041c5fc7439c3e68ced200ce90f5c241f685d62175ad76d183b11e104b3e6821b4f16fdd8b8517b069c6b59e0cc9164b6fa7691a21325f5dac6a5
6
+ metadata.gz: 4a876a9c4ab0c915ebe9e62d1ebedc7e4c3446dd0900394d32cae22f5d89d799523249c5185f8057194a9d1535bfcf637ae5f6ac641d3775b9049d944a9661df
7
+ data.tar.gz: 7bc2234cc3f8f1ef1fa253565d195a4d43661842fc2218c283e8c93406676bab3b792dab3d514b97ae4edd2c97d9d6793af6119a034caac539fe19a05c8adaea
@@ -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
- return amount if amount.is_a?(String) && (amount.index('.').nil? || amount.index(',').nil?)
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
@@ -7,6 +7,10 @@ class String
7
7
  self.to_i.to_s == self
8
8
  end
9
9
 
10
+ def float?
11
+ self.to_f.to_s == self
12
+ end
13
+
10
14
  def equals?(str)
11
15
  self == str
12
16
  end
data/lib/rents/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Rents
2
2
  MAJOR = 1
3
3
  MINOR = 0
4
- PATCH = 5
4
+ PATCH = 6
5
5
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
6
6
  end
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
- sold_items.push({
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
- return sold_items
32
+ sold_items
31
33
  end
32
34
 
33
35
  def get_json url
@@ -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.0
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.5
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-04 00:00:00.000000000 Z
11
+ date: 2015-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler