lab42_rgxargs 0.1.0.pre → 0.1.0

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: 00f0a79cda8803391dd5e2f9e21cdc06c7032be12741542b1d715bd044623182
4
- data.tar.gz: 47ad2d322cdd22197b63378d76097523544f7f141077d44d5e1127884b73e042
3
+ metadata.gz: 1284c83060453b9b65c017381fb3afb8388a2bff50bc256bfd1d4456f46a94d1
4
+ data.tar.gz: 8e51fe32f62a1d16b6ba4e6a7b99a6011e203041c5dcd7b19cce3ed751af818d
5
5
  SHA512:
6
- metadata.gz: acf4d6f1e22bae17cfe89070e4a5a3e58650838d24e99545b75ab9c06c7b04fffeb3eecdcdbc131337a2324c0ac297ae16ac56c8d46adf85224ab92a42977fe5
7
- data.tar.gz: bea5ef2c6b7d4d48645b6affd40716b5e14f57afc98ecc4d5fca045e530ae0ca52bfbf1148f763a0af97b069acd4c968f7dae83ac7f4e97bfe0e8b8637b4d251
6
+ metadata.gz: 428e2088c5f440857f952069a63e9dce4cb33e7ee331d4b7bfbde2bbaa7d9e623ed74b121a93650e8621c3c80e536b50761d1dfbcc04dbaba84bbee9210b238f
7
+ data.tar.gz: 2b455ae68e0a12c97a43f4395d3d49dcd0ca059532db4489fc71e2b17c74e664d8b422194e550fcec30992d16a0febe7294e641043bf1926bea7eb84fce136c4
@@ -1,14 +1,27 @@
1
1
  module Lab42::Rgxargs::PredefinedMatchers extend self
2
2
  PREDEFINED = {
3
- list: [%r{(\w+)(?:,(\w+))*}, ->(groups){ groups }],
3
+ int_list: [%r{\A(-?\d+(?:,-?\d+)*)\z}, ->(groups){ groups.first.split(",").map(&:to_i)}],
4
+ int_range: [%r{\A(-?\d+)(?:-|\.\.)(-?\d+)\z}, ->((f, l)){ Range.new(f.to_i, l.to_i) }],
5
+ list: [%r{(\w+)(?:,(\w+))*}, ->(groups){ groups.compact }],
4
6
  range: [%r{\A(\d+)\.\.(\d+)\z}, ->(groups){ Range.new(*groups.map(&:to_i)) }]
5
7
  }
6
8
 
7
9
  def defined_names
8
10
  @__defined_names__ ||= PREDEFINED.keys.join("\n\t")
9
11
  end
12
+
10
13
  def fetch(key, default=nil, &blk)
11
14
  return PREDEFINED[key] if PREDEFINED.has_key?(key)
12
15
  blk ? blk.(key) : default
13
16
  end
17
+
18
+ def list_matcher values
19
+ [%r{\A((?:#{values.join("|")})(?:,(?:#{values.join("|")}))*)\z}, _list_extractor]
20
+ end
21
+
22
+
23
+ # Memoized
24
+ def _list_extractor
25
+ @__list_extractor__ ||= ->(groups){ groups.first.split(",") }
26
+ end
14
27
  end
data/lib/lab42/rgxargs.rb CHANGED
@@ -1,11 +1,17 @@
1
+ require 'forwardable'
1
2
  require 'ostruct'
2
3
  require 'lab42/enumerable'
4
+
3
5
  class Lab42::Rgxargs
4
6
  require_relative 'rgxargs/predefined_matchers'
5
7
  Predefined = PredefinedMatchers
6
8
 
9
+ extend Forwardable
10
+ def_delegators Predefined, :list_matcher
11
+
7
12
  attr_reader :args, :conversions, :defined_rules, :errors, :options, :syntaxes
8
13
 
14
+
9
15
  def add_conversion(param, conversion)
10
16
  case conversion
11
17
  when Symbol
@@ -27,7 +33,6 @@ class Lab42::Rgxargs
27
33
  end
28
34
  end
29
35
 
30
-
31
36
  def parse argv
32
37
  until argv.empty?
33
38
  argv = _parse_next argv
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.0.pre
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
@@ -62,9 +62,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 1.3.1
67
+ version: '0'
68
68
  requirements: []
69
69
  rubygems_version: 3.0.6
70
70
  signing_key: