valuable 0.9.0 → 0.9.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/.gitignore +2 -0
- data/lib/valuable/utils.rb +14 -1
- data/test/typical_test.rb +14 -0
- data/valuable.version +1 -1
- metadata +3 -3
data/.gitignore
CHANGED
data/lib/valuable/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
|
1
3
|
module Valuable::Utils
|
2
4
|
class << self
|
3
5
|
|
@@ -47,6 +49,17 @@ module Valuable::Utils
|
|
47
49
|
|
48
50
|
value && value.to_i
|
49
51
|
|
52
|
+
when :decimal
|
53
|
+
|
54
|
+
case value
|
55
|
+
when NilClass
|
56
|
+
nil
|
57
|
+
when BigDecimal
|
58
|
+
value
|
59
|
+
else
|
60
|
+
BigDecimal.new( value.to_s )
|
61
|
+
end
|
62
|
+
|
50
63
|
when :string
|
51
64
|
|
52
65
|
value && value.to_s
|
@@ -70,7 +83,7 @@ module Valuable::Utils
|
|
70
83
|
end
|
71
84
|
|
72
85
|
def klass_options
|
73
|
-
[NilClass, :date, :
|
86
|
+
[NilClass, :integer, Class, :date, :decimal, :string, :boolean]
|
74
87
|
end
|
75
88
|
|
76
89
|
def known_options
|
data/test/typical_test.rb
CHANGED
@@ -8,6 +8,10 @@ class Person < Valuable
|
|
8
8
|
has_value :dob, :klass => :date
|
9
9
|
end
|
10
10
|
|
11
|
+
class Chemical < Valuable
|
12
|
+
has_value :ph, :klass => :decimal
|
13
|
+
end
|
14
|
+
|
11
15
|
class TypicalTest < Test::Unit::TestCase
|
12
16
|
|
13
17
|
def test_that_dates_can_be_set_directly
|
@@ -42,5 +46,15 @@ class TypicalTest < Test::Unit::TestCase
|
|
42
46
|
animal.has_value :species, :klass => :invalid
|
43
47
|
end
|
44
48
|
end
|
49
|
+
|
50
|
+
def test_that_decimals_typified
|
51
|
+
lemon_juice = Chemical.new(:ph => 1.8)
|
52
|
+
assert_kind_of BigDecimal, lemon_juice.ph
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_that_nil_input_is_preserved_for_decimals
|
56
|
+
lemon_juice = Chemical.new(:ph => nil)
|
57
|
+
assert_equal nil, lemon_juice.ph
|
58
|
+
end
|
45
59
|
end
|
46
60
|
|
data/valuable.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.1
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valuable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 57
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 1
|
10
|
+
version: 0.9.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Johnathon Wright
|