lab42_rgxargs 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lab42/rgxargs/predefined_matchers.rb +2 -2
- data/lib/lab42/rgxargs.rb +11 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d995928882bad168df974b923ccb5d725eb86bbd56a694cedd9059ef568e6ad
|
4
|
+
data.tar.gz: 4e4194883792088934889ebd8f7a6fdcd6126ad55cf1fa3a0eb30249ad938d0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb3138610aa1d243ed7bc5d7b7b782901b788d5b75b50e227f7cc0d5ba3ca0f524f8f501139bb67ac808a4b697f915afe89312a0c2f3ec4bf4396cce81d75908
|
7
|
+
data.tar.gz: f662d35d67de38063f978716ca85a9e68548c71dd428867e4354d3706b6d070a3c5efd4fd18e3e55ac375aba9a7b218f5fe5fefe04e63a33e407646fbfd54671
|
@@ -10,8 +10,8 @@ module Lab42::Rgxargs::PredefinedMatchers extend self
|
|
10
10
|
@__defined_names__ ||= PREDEFINED.keys.join("\n\t")
|
11
11
|
end
|
12
12
|
|
13
|
-
def fetch(key, default=nil, &blk)
|
14
|
-
return PREDEFINED[key] if PREDEFINED.has_key?(key)
|
13
|
+
def fetch(key, default=nil, as: nil, &blk)
|
14
|
+
return PREDEFINED[key] + [as] if PREDEFINED.has_key?(key)
|
15
15
|
blk ? blk.(key) : default
|
16
16
|
end
|
17
17
|
|
data/lib/lab42/rgxargs.rb
CHANGED
@@ -22,11 +22,11 @@ module Lab42
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def add_syntax(rgx, parser=nil)
|
25
|
+
def add_syntax(rgx, parser=nil, as: nil)
|
26
26
|
if parser
|
27
|
-
syntaxes << [rgx, parser]
|
27
|
+
syntaxes << [rgx, parser, as]
|
28
28
|
else
|
29
|
-
if predef = Predefined.fetch(rgx)
|
29
|
+
if predef = Predefined.fetch(rgx, as: as)
|
30
30
|
syntaxes << predef
|
31
31
|
else
|
32
32
|
raise ArgumentError, "#{rgx} is not a predefined syntax, use one of the following:\n\t#{Predefined.defined_names}"
|
@@ -64,7 +64,7 @@ module Lab42
|
|
64
64
|
conv.(value)
|
65
65
|
when Array
|
66
66
|
if (match = conv.first.match(value))
|
67
|
-
conv.
|
67
|
+
conv[1].(match.captures)
|
68
68
|
else
|
69
69
|
errors << [:syntax_error, name, "#{value} does not match #{conv.first}"]
|
70
70
|
nil
|
@@ -100,8 +100,13 @@ module Lab42
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def _parse_syntax first
|
103
|
-
|
104
|
-
(match = rgx.match(first)) && converter.(match.captures)
|
103
|
+
value, as = syntaxes.find_value(first) do |(rgx, converter, as)|
|
104
|
+
(match = rgx.match(first)) && [converter.(match.captures), as]
|
105
|
+
end
|
106
|
+
if as
|
107
|
+
options[as] = value
|
108
|
+
else
|
109
|
+
args << value
|
105
110
|
end
|
106
111
|
end
|
107
112
|
|