decanter 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/decanter/core.rb +1 -0
- data/lib/decanter/parser/core.rb +5 -1
- data/lib/decanter/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: 99d5bfae4e2f4ed374e9851fd07d53d524963349
|
4
|
+
data.tar.gz: ad634273515df9853b3566948a1dcf61884d5b80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09420cff51f63c0971a7dc1651b27078d209588f65373608c3be654dbea9bfad1d4ef0727b7170c8aa9bf65d271220c396e7d0f0ed01c028ccb64d2e3e1ec9b0
|
7
|
+
data.tar.gz: 03dd595cc9e0f01ca5963d8fdb88763300990a018ec639c7d093bd6098d1fb18c6e7ffde8a07c663adc911d43ab7a54cddb1f5b66c371b0aaaf0fccaf97e00b1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -384,7 +384,7 @@ Chaining Parsers
|
|
384
384
|
Parsers are composable! Suppose you want a parser that takes an incoming percentage like "50.3%" and converts it into a float for your database like .503. You could implement this with:
|
385
385
|
|
386
386
|
```ruby
|
387
|
-
class PercentParser < ValueParser
|
387
|
+
class PercentParser < Decanter::Parser::ValueParser
|
388
388
|
REGEX = /(\d|[.])/
|
389
389
|
|
390
390
|
parser do |val, options|
|
@@ -397,7 +397,7 @@ end
|
|
397
397
|
This works, but it duplicates logic that already exists in `FloatParser`. Instead, you can specify a parser that should always run before your parsing logic, then you can assume that your parser receives a float:
|
398
398
|
|
399
399
|
```ruby
|
400
|
-
class SmartPercentParser < ValueParser
|
400
|
+
class SmartPercentParser < Decanter::Parser::ValueParser
|
401
401
|
|
402
402
|
pre :float
|
403
403
|
|
data/lib/decanter/core.rb
CHANGED
data/lib/decanter/parser/core.rb
CHANGED
@@ -11,7 +11,7 @@ module Decanter
|
|
11
11
|
# Check if allowed, parse if not
|
12
12
|
def parse(name, values, options={})
|
13
13
|
case
|
14
|
-
when allowed?(values)
|
14
|
+
when allowed?(values) || empty_values?(values)
|
15
15
|
{ name => values }
|
16
16
|
else
|
17
17
|
_parse(name, values, options)
|
@@ -44,6 +44,10 @@ module Decanter
|
|
44
44
|
@allowed.any? { |allowed| value.is_a? allowed }
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
def empty_values?(values)
|
49
|
+
return true if Array.wrap(values).all? { |value| value.nil? || value == "" }
|
50
|
+
end
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
data/lib/decanter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decanter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Francis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|