gci-class-extensions 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,7 @@ end
46
46
  class String
47
47
  def is_valid_dollar_amount?
48
48
  # Optional parentheses or negative sign before or after the optional dollar sign, any number of digits and commas, followed by optional . and 1 or 2 digits, and optional close parentheses, with nothing on either side
49
- strip =~ /^[\(-]?\$?[\(-]?([\d,]+(\.\d{1,2})?|\.\d{1,2})\)?$/ ? true : false
49
+ strip =~ /^[\(-]?\$?[\(-]?[\d,]+(\.\d{1,2})?\)?$/ ? true : false
50
50
  end
51
51
 
52
52
  def scrubbed_dollar_amount
@@ -62,10 +62,6 @@ class String
62
62
  def escape_sql
63
63
  self.gsub(/\\/, '\&\&').gsub(/'/, "''")
64
64
  end
65
-
66
- def to_dollar_amount
67
- is_valid_dollar_amount? ? scrubbed_dollar_amount.to_f.round(2) : 0.0
68
- end
69
65
  end
70
66
 
71
67
  # TODO write a spec
@@ -74,10 +70,3 @@ class Float
74
70
  (self * 100).round(precision)
75
71
  end
76
72
  end
77
-
78
- class Fixnum
79
- # we ignore the precision and just return itself as a float, since Float#to_f accepts this parameter
80
- def round(precision=2)
81
- to_f
82
- end
83
- end
@@ -88,8 +88,6 @@ end
88
88
 
89
89
  describe String, "knowing whether it contains a valid dollar amount" do
90
90
  valid_amounts = [
91
- # less than a dollar
92
- ".50", "0.50", ".25",
93
91
  # simple numbers with dollar signs
94
92
  "$123", "$123.45", "$123,456", "$123,456.78",
95
93
  # simple numbers without dollar signs
@@ -141,33 +139,6 @@ describe String, "when scrubbing the dollar amounts to only the digits" do
141
139
  it "should leave the string alone if has no dollar sign or commas" do
142
140
  "123".scrubbed_dollar_amount.should == "123"
143
141
  end
144
-
145
- it "should convert the string to a dollar with two decimals" do
146
- '123.12'.to_dollar_amount.should == 123.12
147
- end
148
-
149
- it "should return 0.0 if the string has > 2 decimal places" do
150
- '123.1234'.to_dollar_amount.should == 0.0
151
- end
152
-
153
- it "should return 0.0 if the string is not a valid $ amount" do
154
- "xcv".to_dollar_amount.should == 0.0
155
- end
156
-
157
- end
158
-
159
- describe Fixnum, "accepting a parameter to round as float does" do
160
- it "should ignore the parameter and just return itself" do
161
- 1.round(2).should == 1.0
162
- 7.round(9).should == 7.0
163
- 0.round(123456789).should == 0.0
164
- end
165
-
166
- it "should accept no parameter" do
167
- 1.round.should == 1.0
168
- 7.round.should == 7.0
169
- 0.round.should == 0.0
170
- end
171
142
  end
172
143
 
173
144
  describe Float, "knowing its value as a percentage" do
@@ -185,3 +156,9 @@ describe Float, "knowing its value as a percentage" do
185
156
  (6.543212).to_percentage(3).should == 654.321
186
157
  end
187
158
  end
159
+
160
+ # class Float
161
+ # def to_percentage(precision=2)
162
+ # (self * 100).round(precision)
163
+ # end
164
+ # end
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gci-class-extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- - 2
10
- version: 1.1.2
4
+ version: 1.2.0
11
5
  platform: ruby
12
6
  authors:
13
7
  - Patrick Byrne
@@ -15,36 +9,29 @@ autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
11
 
18
- date: 2012-03-31 00:00:00 Z
12
+ date: 2010-07-19 00:00:00 -05:00
13
+ default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: active_support
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
25
20
  requirements:
26
21
  - - ">="
27
22
  - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
23
  version: "0"
32
- type: :runtime
33
- version_requirements: *id001
24
+ version:
34
25
  - !ruby/object:Gem::Dependency
35
26
  name: valid-date
36
- prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
39
30
  requirements:
40
31
  - - ">="
41
32
  - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
33
  version: "0"
46
- type: :runtime
47
- version_requirements: *id002
34
+ version:
48
35
  description:
49
36
  email: code@patrickbyrne.net
50
37
  executables: []
@@ -56,7 +43,7 @@ extra_rdoc_files:
56
43
  files:
57
44
  - lib/gci-class-extensions.rb
58
45
  - README
59
- - spec/gci-class-extensions_spec.rb
46
+ has_rdoc: true
60
47
  homepage: http://bitbucket.org/pbyrne/common-ruby-class-extensions/
61
48
  licenses: []
62
49
 
@@ -66,27 +53,21 @@ rdoc_options: []
66
53
  require_paths:
67
54
  - lib
68
55
  required_ruby_version: !ruby/object:Gem::Requirement
69
- none: false
70
56
  requirements:
71
57
  - - ">="
72
58
  - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
59
  version: "0"
60
+ version:
77
61
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
62
  requirements:
80
63
  - - ">="
81
64
  - !ruby/object:Gem::Version
82
- hash: 3
83
- segments:
84
- - 0
85
65
  version: "0"
66
+ version:
86
67
  requirements: []
87
68
 
88
69
  rubyforge_project:
89
- rubygems_version: 1.8.6
70
+ rubygems_version: 1.3.5
90
71
  signing_key:
91
72
  specification_version: 3
92
73
  summary: A gem used by our internal team for common class extensions, like not_blank? and not_nil? counterparts to blank? and nil?.