nrser 0.2.0.pre.0 → 0.2.0.pre.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.
- checksums.yaml +4 -4
- data/lib/nrser/functions/hash/symbolize_keys.rb +1 -1
- data/lib/nrser/types/combinators.rb +42 -15
- data/lib/nrser/types/is.rb +3 -1
- data/lib/nrser/types/paths.rb +1 -0
- data/lib/nrser/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 942988b83ec5c05fed5f15e87869dd0f20044db8
|
4
|
+
data.tar.gz: 57bc680b81ffe4f7650b1200d0aa21a8579be60a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eec00863e1a07aa333d71a66139773d7f198efcfa137e6aa57607d619431854a2850e54e7ae59c8e1dbbc28f9bd887969f36aef584d703bb0830a345e1540bb9
|
7
|
+
data.tar.gz: 3129461e852e4a830e7dcf0dd097c32e017fa4e99541ed76f1bb9670025575a6ec9f3570ad9390a397f6ca733a051b5349d0865a5103656a0bf22be5948e4f7c
|
@@ -31,19 +31,41 @@ module NRSER::Types
|
|
31
31
|
end
|
32
32
|
|
33
33
|
|
34
|
-
# a
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# a
|
42
|
-
#
|
43
|
-
#
|
34
|
+
# Parse a satisfying value from a {String} or raise a {TypeError}.
|
35
|
+
#
|
36
|
+
# If this type has it's own `@from_s` that was provided via the `from_s:`
|
37
|
+
# keyword at construction, then that and **only** that is **always** used
|
38
|
+
# - the type will never try any of the combined types' `#from_s`.
|
39
|
+
#
|
40
|
+
# It's considered *the* way to parse a string into a value that satisfies
|
41
|
+
# the type. If it fails, a {TypeError} will be raised (or any error the
|
42
|
+
# `@from_s` proc itself raises before we get to checking it).
|
43
|
+
#
|
44
|
+
# If the type doesn't have it's own `@from_s`, each of the combined types'
|
45
|
+
# `#from_s` will be tried in sequence, and the first value that satisfies
|
46
|
+
# the combined type will be returned.
|
47
|
+
#
|
48
|
+
# This is obviously much less efficient, but provides a nice automatic
|
49
|
+
# mechanism for parsing from strings for combined types. If none of the
|
50
|
+
# combined types' `#from_s` succeed (or if there are none) a {TypeError}
|
51
|
+
# is raised.
|
52
|
+
#
|
53
|
+
# @param [String] s
|
54
|
+
# String to parse.
|
55
|
+
#
|
56
|
+
# @return [Object]
|
57
|
+
# Object that satisfies the type.
|
58
|
+
#
|
59
|
+
# @raise [TypeError]
|
60
|
+
# See write up above.
|
61
|
+
#
|
44
62
|
def from_s s
|
63
|
+
unless @from_s.nil?
|
64
|
+
return check @from_s.call( s )
|
65
|
+
end
|
66
|
+
|
45
67
|
@types.each { |type|
|
46
|
-
if type.
|
68
|
+
if type.has_from_s?
|
47
69
|
begin
|
48
70
|
return check type.from_s(s)
|
49
71
|
rescue TypeError => e
|
@@ -57,15 +79,20 @@ module NRSER::Types
|
|
57
79
|
end
|
58
80
|
|
59
81
|
|
60
|
-
# Overridden to delegate functionality to the combined types
|
82
|
+
# Overridden to delegate functionality to the combined types.
|
83
|
+
#
|
84
|
+
# A combinator may attempt to parse from a string if:
|
85
|
+
#
|
86
|
+
# 1. It has it's own `@from_s` provided at construction.
|
87
|
+
#
|
88
|
+
# 2. Any of it's combined types can parse from a string.
|
61
89
|
#
|
62
|
-
#
|
63
|
-
# can do so.
|
90
|
+
# See {#from_s} for details of how it actually happens.
|
64
91
|
#
|
65
92
|
# @return [Boolean]
|
66
93
|
#
|
67
94
|
def has_from_s?
|
68
|
-
@types.any? {|type| type.has_from_s?}
|
95
|
+
super() || @types.any? { |type| type.has_from_s? }
|
69
96
|
end # has_from_s
|
70
97
|
|
71
98
|
|
data/lib/nrser/types/is.rb
CHANGED
data/lib/nrser/types/paths.rb
CHANGED
data/lib/nrser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nrser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0.pre.
|
4
|
+
version: 0.2.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hamster
|
@@ -431,7 +431,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
431
431
|
version: 1.3.1
|
432
432
|
requirements: []
|
433
433
|
rubyforge_project:
|
434
|
-
rubygems_version: 2.5.2
|
434
|
+
rubygems_version: 2.5.2.2
|
435
435
|
signing_key:
|
436
436
|
specification_version: 4
|
437
437
|
summary: basic ruby utils i use in a lot of stuff.
|