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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad2ab026f6192cc81dd04008d035a79188ed42723b4d687a536a49c010d8a0db
4
- data.tar.gz: b4503cbb9403aec807fb871c5d901690d6ba026edb8c6b6080e0af4506b6e2a7
3
+ metadata.gz: 9d995928882bad168df974b923ccb5d725eb86bbd56a694cedd9059ef568e6ad
4
+ data.tar.gz: 4e4194883792088934889ebd8f7a6fdcd6126ad55cf1fa3a0eb30249ad938d0a
5
5
  SHA512:
6
- metadata.gz: e41fc413182c5a6e6ca070c8980b9356738df2b956915c1fdf55849136642ff36b97cef4ee01e1fc3505269a7f9c7b9328044bd8c7a1d4b3401e08aa8820a5b8
7
- data.tar.gz: e75cbfc5b427e68838513444862d0e3ccca90fe5363f517fe24f40beae2655c830c020f2c55559375069bfe837c4ab55940559f3625e318656b12c9c4ff3d5cc
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.last.(match.captures)
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
- args << syntaxes.find_value(first) do |(rgx, converter)|
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_rgxargs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober