acts_as_decimal 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_decimal}
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oriol Gual", "Josep M. Bach", "Josep Jaume Rey"]
12
- s.date = %q{2010-08-09}
12
+ s.date = %q{2010-08-13}
13
13
  s.description = %q{Rails 3 gem to treat an attribute as a decimal (getting and setting floating-point values) but storing it as an integer in the database (useful for prices and other precision-needed attributes like money).}
14
14
  s.email = %q{info@codegram.com}
15
15
  s.extra_rdoc_files = [
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
37
37
  s.homepage = %q{http://github.com/codegram/acts_as_decimal}
38
38
  s.rdoc_options = ["--charset=UTF-8"]
39
39
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.3.7}
40
+ s.rubygems_version = %q{1.3.6}
41
41
  s.summary = %q{Treat an attribute as if it were a decimal, storing it as an integer in the database.}
42
42
  s.test_files = [
43
43
  "spec/acts_as_decimal_spec.rb",
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
50
  s.specification_version = 3
51
51
 
52
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
53
  s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0.rc"])
54
54
  s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
55
55
  s.add_development_dependency(%q<activerecord>, [">= 3.0.0.rc"])
@@ -19,9 +19,10 @@ module ActsAsDecimal
19
19
  fields.each do |field|
20
20
  class_eval <<-EOC
21
21
  def #{field}
22
- (self[:#{field}].nil? ? nil : (BigDecimal.new(self[:#{field}].to_s) / BigDecimal('10').power(#{options[:decimals]})).to_f)
22
+ # DOES NOT WORK PROPERLY WITH VIM (WTF¿?): (self[:#{field}].nil? ? nil : (BigDecimal.new(self[:#{field}].to_s) / BigDecimal('10').power(#{options[:decimals]})).to_f)
23
+ (self[:#{field}].nil? ? nil : (self[:#{field}] / BigDecimal('10').power(#{options[:decimals]}).to_f))
23
24
  end
24
- def humanized_#{field}(options = {:thousand_delimiters => true})
25
+ def human_#{field}(options = {:thousand_delimiters => true})
25
26
 
26
27
  return nil if #{field}.blank?
27
28
 
@@ -34,7 +35,13 @@ module ActsAsDecimal
34
35
  groups = a[0].reverse.scan(/\\d{3}/)
35
36
  rest = a[0].gsub(groups.join.reverse, '').reverse
36
37
  groups << rest unless rest.empty?
37
- return groups.join('.').reverse + "," + b
38
+ if groups.last == '-'
39
+ groups.reject!{|x| x == '-'}
40
+ negative = true
41
+ end
42
+ humanized_string = negative ? "-" : ""
43
+ humanized_string += groups.join('.').reverse + "," + b
44
+ return humanized_string
38
45
  end
39
46
 
40
47
  end
@@ -55,4 +62,3 @@ module ActsAsDecimal
55
62
  end
56
63
 
57
64
  end
58
-
@@ -41,18 +41,18 @@ describe Product do
41
41
 
42
42
  end
43
43
 
44
- describe "humanized helpers", "when retrieving the humanized value (as a string)" do
44
+ describe "human helpers", "when retrieving the human value (a pretty string)" do
45
45
 
46
46
  context "with a 3.900.400,00 price" do
47
47
 
48
- subject { Product.new(:price => 3900400.00) }
48
+ subject { Product.new(:price => 3_900_400.00) }
49
49
 
50
- it "has a humanized_price of 3.900.400,00" do
51
- subject.humanized_price.should == "3.900.400,00"
50
+ it "has a human_price of 3.900.400,00" do
51
+ subject.human_price.should == "3.900.400,00"
52
52
  end
53
53
 
54
- it "has a humanized_price(:thousand_delimiters => false) of 3900400.00" do
55
- subject.humanized_price(:thousand_delimiters => false).should == "3900400.00"
54
+ it "has a human_price(:thousand_delimiters => false) of 3900400.00" do
55
+ subject.human_price(:thousand_delimiters => false).should == "3900400.00"
56
56
  end
57
57
 
58
58
  end
@@ -61,12 +61,12 @@ describe Product do
61
61
 
62
62
  subject { Product.new(:price => 20000.00) }
63
63
 
64
- it "has a humanized_price of 20.000,00" do
65
- subject.humanized_price.should == "20.000,00"
64
+ it "has a human_price of 20.000,00" do
65
+ subject.human_price.should == "20.000,00"
66
66
  end
67
67
 
68
- it "has a humanized_price(:thousand_delimiters => false) of 20000.00" do
69
- subject.humanized_price(:thousand_delimiters => false).should == "20000.00"
68
+ it "has a human_price(:thousand_delimiters => false) of 20000.00" do
69
+ subject.human_price(:thousand_delimiters => false).should == "20000.00"
70
70
  end
71
71
 
72
72
  end
@@ -75,12 +75,12 @@ describe Product do
75
75
 
76
76
  subject { Product.new(:price => 900.00) }
77
77
 
78
- it "has a humanized_price of 900,00" do
79
- subject.humanized_price.should == "900,00"
78
+ it "has a human_price of 900,00" do
79
+ subject.human_price.should == "900,00"
80
80
  end
81
81
 
82
- it "has a humanized_price(:thousand_delimiters => false) of 900.00" do
83
- subject.humanized_price(:thousand_delimiters => false).should == "900.00"
82
+ it "has a human_price(:thousand_delimiters => false) of 900.00" do
83
+ subject.human_price(:thousand_delimiters => false).should == "900.00"
84
84
  end
85
85
 
86
86
  end
@@ -89,15 +89,43 @@ describe Product do
89
89
 
90
90
  subject { Product.new(:price => "900.00") }
91
91
 
92
- it "has a humanized_price of 900,00" do
93
- subject.humanized_price.should == "900,00"
92
+ it "has a human_price of 900,00" do
93
+ subject.human_price.should == "900,00"
94
94
  end
95
95
 
96
- it "has a humanized_price(:thousand_delimiters => false) of 900.00" do
97
- subject.humanized_price(:thousand_delimiters => false).should == "900.00"
96
+ it "has a human_price(:thousand_delimiters => false) of 900.00" do
97
+ subject.human_price(:thousand_delimiters => false).should == "900.00"
98
98
  end
99
99
 
100
100
  end
101
+
102
+ context "with a negative float price -900.00" do
103
+
104
+ subject { Product.new(:price => -900.00) }
105
+
106
+ it "has a human_price of -900,00" do
107
+ subject.human_price.should == "-900,00"
108
+ end
109
+
110
+ it "has a human_price(:thousand_delimiters => false) of -900.00" do
111
+ subject.human_price(:thousand_delimiters => false).should == "-900.00"
112
+ end
113
+
114
+ end
115
+
116
+ context "with a negative string price '-900.00'" do
117
+
118
+ subject { Product.new(:price => "-900.00") }
119
+
120
+ it "has a human_price of -900,00" do
121
+ subject.human_price.should == "-900,00"
122
+ end
123
+
124
+ it "has a human_price(:thousand_delimiters => false) of -900.00" do
125
+ subject.human_price(:thousand_delimiters => false).should == "-900.00"
126
+ end
127
+
128
+ end
101
129
  end
102
130
 
103
131
  context "with a price of 10.30452 and specifying :decimals => 5" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 3
9
- version: 1.0.3
8
+ - 4
9
+ version: 1.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Oriol Gual
@@ -16,14 +16,13 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-09 00:00:00 +02:00
19
+ date: 2010-08-13 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: activemodel
24
24
  prerelease: false
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
27
26
  requirements:
28
27
  - - ">="
29
28
  - !ruby/object:Gem::Version
@@ -39,7 +38,6 @@ dependencies:
39
38
  name: rspec
40
39
  prerelease: false
41
40
  requirement: &id002 !ruby/object:Gem::Requirement
42
- none: false
43
41
  requirements:
44
42
  - - ">="
45
43
  - !ruby/object:Gem::Version
@@ -56,7 +54,6 @@ dependencies:
56
54
  name: activerecord
57
55
  prerelease: false
58
56
  requirement: &id003 !ruby/object:Gem::Requirement
59
- none: false
60
57
  requirements:
61
58
  - - ">="
62
59
  - !ruby/object:Gem::Version
@@ -104,7 +101,6 @@ rdoc_options:
104
101
  require_paths:
105
102
  - lib
106
103
  required_ruby_version: !ruby/object:Gem::Requirement
107
- none: false
108
104
  requirements:
109
105
  - - ">="
110
106
  - !ruby/object:Gem::Version
@@ -112,7 +108,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
108
  - 0
113
109
  version: "0"
114
110
  required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
111
  requirements:
117
112
  - - ">="
118
113
  - !ruby/object:Gem::Version
@@ -122,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
117
  requirements: []
123
118
 
124
119
  rubyforge_project:
125
- rubygems_version: 1.3.7
120
+ rubygems_version: 1.3.6
126
121
  signing_key:
127
122
  specification_version: 3
128
123
  summary: Treat an attribute as if it were a decimal, storing it as an integer in the database.