ShadowBelmolve-money 2.3.7 → 2.3.8

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.7
1
+ 2.3.8
@@ -10,7 +10,7 @@ class Numeric
10
10
  if self.is_a? Integer
11
11
  Money.new(self)
12
12
  else
13
- Money.new(self.to_s.gsub(/\./,'').round)
13
+ Money.new(self.to_s.gsub(/\./,'').to_i)
14
14
  end
15
15
  else
16
16
  Money.new((self * 100).round)
@@ -28,17 +28,17 @@ class String
28
28
  # 'USD 100'.to_money # => #<Money @cents=10000, @currency="USD">
29
29
  # '$100 USD'.to_money # => #<Money @cents=10000, @currency="USD">
30
30
  # 'hello 2000 world'.to_money # => #<Money @cents=200000 @currency="USD")>
31
- def to_money
31
+ def to_money(with_cents = false)
32
32
  # Get the currency.
33
33
  matches = scan /([A-Z]{2,3})/
34
34
  currency = matches[0] ? matches[0][0] : Money.default_currency
35
- cents = calculate_cents(self)
35
+ cents = calculate_cents(self, with_cents)
36
36
  Money.new(cents, currency)
37
37
  end
38
38
 
39
39
  private
40
40
 
41
- def calculate_cents(number)
41
+ def calculate_cents(number, with_cents)
42
42
  # remove anything that's not a number, potential delimiter, or minus sign
43
43
  num = number.gsub(/[^\d|\.|,|\'|\s|\-]/, '').strip
44
44
 
@@ -127,17 +127,21 @@ class String
127
127
 
128
128
  # build the string based on major/minor since separator/delimiters have been removed
129
129
  # avoiding floating point arithmetic here to ensure accuracy
130
- cents = (major.to_i * 100)
131
- # add the minor number as well. this may have any number of digits,
132
- # so we treat minor as a string and truncate or right-fill it with zeroes
133
- # until it becomes a two-digit number string, which we add to cents.
134
- minor = minor.to_s
135
- truncated_minor = minor[0..1]
136
- truncated_minor << "0" * (2 - truncated_minor.size) if truncated_minor.size < 2
137
- cents += truncated_minor.to_i
138
- # respect rounding rules
139
- if minor.size >= 3 && minor[2..2].to_i >= 5
140
- cents += 1
130
+ if with_cents and minor == 0
131
+ cents = major.to_i
132
+ else
133
+ cents = major.to_i * 100
134
+ # add the minor number as well. this may have any number of digits,
135
+ # so we treat minor as a string and truncate or right-fill it with zeroes
136
+ # until it becomes a two-digit number string, which we add to cents.
137
+ minor = minor.to_s
138
+ truncated_minor = minor[0..1]
139
+ truncated_minor << "0" * (2 - truncated_minor.size) if truncated_minor.size < 2
140
+ cents += truncated_minor.to_i
141
+ # respect rounding rules
142
+ if minor.size >= 3 && minor[2..2].to_i >= 5
143
+ cents += 1
144
+ end
141
145
  end
142
146
 
143
147
  # if negative, multiply by -1; otherwise, return positive cents
data/money.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{money}
5
- s.version = "2.3.7"
5
+ s.version = "2.3.8"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Money Team"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ShadowBelmolve-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.7
4
+ version: 2.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Money Team