subroutine 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subroutine/type_caster.rb +7 -8
- data/lib/subroutine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d28f248f1e76c10fb53fcbf1fc376a7f2c6800cd
|
4
|
+
data.tar.gz: b81a6050e1c2245e545b39dd99d396f80925a92e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27f2215a662339b46a5bd7a73a1822915d95a9144fc28f09dac0bd632020629d2ca6ec6aab6497a5c7b3452946b816dd8cdb5fbe99e96a359ac11e9f205915c6
|
7
|
+
data.tar.gz: 260a8d6f175d715175376c8072d25318b0db4c467cff433c95458ede1788bd985c9ef0619e0ad3db4d707ef3978820a259e0af5c22b58edc51a60014533c18d2
|
@@ -29,12 +29,11 @@ module Subroutine
|
|
29
29
|
|
30
30
|
case type.to_sym
|
31
31
|
when *TYPES[:integer]
|
32
|
-
cast_number(value
|
32
|
+
cast_number(value, :to_i)
|
33
33
|
when *TYPES[:number]
|
34
|
-
cast_number(value
|
34
|
+
cast_number(value, :to_f)
|
35
35
|
when *TYPES[:decimal]
|
36
|
-
|
37
|
-
d ? BigDecimal(d.to_s) : nil
|
36
|
+
cast_number(value, :to_d, :to_f)
|
38
37
|
when *TYPES[:string]
|
39
38
|
cast_string(value)
|
40
39
|
when *TYPES[:boolean]
|
@@ -59,10 +58,10 @@ module Subroutine
|
|
59
58
|
|
60
59
|
protected
|
61
60
|
|
62
|
-
def cast_number(value)
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
def cast_number(value, *meths)
|
62
|
+
return nil if value.blank?
|
63
|
+
meth = meths.detect{|m| value.respond_to?(m) }
|
64
|
+
meth ? value.send(meth) : value
|
66
65
|
end
|
67
66
|
|
68
67
|
def cast_string(value)
|
data/lib/subroutine/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subroutine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|