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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02db9f879b81621b4bf0eb6825644ccb513b7883
4
- data.tar.gz: 6e557fb324b506ed9462fed4825228ff664fdcb7
3
+ metadata.gz: d28f248f1e76c10fb53fcbf1fc376a7f2c6800cd
4
+ data.tar.gz: b81a6050e1c2245e545b39dd99d396f80925a92e
5
5
  SHA512:
6
- metadata.gz: 4c39b6b9e07615d075b497bee62db14fda475cd72e7fe8843d5346e3ce9e99d9c7b251e8fa8984b2b4702d51d4d1f55c5ad51ebd405d32fbc7453bc33fb81460
7
- data.tar.gz: 0d17dca16db07d8873a5701be92f820127de198c6e0c3a02d4db578becb69592f678885d3e675081d12f36015bbdfd7a3dae156e8372115cf691dcfe793dcf60
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).try(:to_i)
32
+ cast_number(value, :to_i)
33
33
  when *TYPES[:number]
34
- cast_number(value).try(:to_f)
34
+ cast_number(value, :to_f)
35
35
  when *TYPES[:decimal]
36
- d = cast_number(value)
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
- val = cast_string(value).strip
64
- return nil if val.blank?
65
- val
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)
@@ -2,7 +2,7 @@ module Subroutine
2
2
 
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 3
5
+ PATCH = 4
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
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.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-03-08 00:00:00.000000000 Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel