scrooge 0.1 → 0.1.1
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/lib/scrooge.rb +10 -1
- data/lib/scrooge/active_record.rb +1 -1
- data/scrooge.gemspec +2 -2
- data/spec/scrooge_spec.rb +17 -3
- metadata +2 -2
data/lib/scrooge.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
module Scrooge
|
2
|
-
VERSION = "0.1"
|
2
|
+
VERSION = "0.1.1"
|
3
3
|
|
4
4
|
class Money
|
5
5
|
include Comparable
|
6
6
|
|
7
|
+
def self.parse(value)
|
8
|
+
if value.is_a?(String)
|
9
|
+
value.gsub!(/\$/, '')
|
10
|
+
value.gsub!(/,/, '')
|
11
|
+
end
|
12
|
+
|
13
|
+
value.to_money
|
14
|
+
end
|
15
|
+
|
7
16
|
def initialize(cents)
|
8
17
|
@cents = cents.to_i
|
9
18
|
end
|
@@ -6,7 +6,7 @@ module Scrooge
|
|
6
6
|
names.each do |name|
|
7
7
|
composed_of name, :class_name => "Scrooge::Money",
|
8
8
|
:mapping => ["#{name}_in_cents", "to_cents"],
|
9
|
-
:converter => lambda {|value| (value || 0)
|
9
|
+
:converter => lambda {|value| Money.parse(value || 0) },
|
10
10
|
:constructor => lambda {|value| value.to_f.as_cents }
|
11
11
|
end
|
12
12
|
end
|
data/scrooge.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "scrooge"
|
3
|
-
s.version = "0.1"
|
4
|
-
s.date = "2010-01-
|
3
|
+
s.version = "0.1.1"
|
4
|
+
s.date = "2010-01-20"
|
5
5
|
|
6
6
|
s.description = "Class to serialize money into the database, works out of the box with ActiveRecord"
|
7
7
|
s.summary = "Scrooge will keep all your money safe. Or at least in the database."
|
data/spec/scrooge_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require "
|
1
|
+
require "scrooge"
|
2
2
|
require "spec"
|
3
3
|
|
4
|
-
include
|
4
|
+
include Scrooge
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe Money do
|
7
7
|
subject { Money.new(175) }
|
8
8
|
|
9
9
|
it "can be interpreted as an integer" do
|
@@ -66,4 +66,18 @@ describe Centipede::Money do
|
|
66
66
|
"12345".as_cents.should == Money.new(12345)
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
describe "parsing money strings" do
|
71
|
+
it "parses decimal points correctly" do
|
72
|
+
Money.parse("15.5").should == 15.5
|
73
|
+
end
|
74
|
+
|
75
|
+
it "ignores dollar signs" do
|
76
|
+
Money.parse("$10").should == 10
|
77
|
+
end
|
78
|
+
|
79
|
+
it "ignores commas" do
|
80
|
+
Money.parse("10,000.00").should == 10_000
|
81
|
+
end
|
82
|
+
end
|
69
83
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrooge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Nicol\xC3\xA1s Sanguinetti"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-20 00:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|