regularity 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 22344c2dea3e06de87e19734043692518fd889d0
4
- data.tar.gz: 4399ef19020b4f183a5d989270eece627dd35835
3
+ metadata.gz: 48cd1ab7ec0e574a8bfac514862124f6c5d3212c
4
+ data.tar.gz: befa666012c4d5f3c728f21dbeff5be08320551b
5
5
  SHA512:
6
- metadata.gz: 7fff9de17ab25f58f59293c038e232bf2625e70f6df3bb529f782b8219ce3bd2e0aaa41c412511b900cad0e981b8555c58478f04754d74cbe2d0b0e239f8ddc1
7
- data.tar.gz: c1ececc9d8080212871bd642d4e0d9c64b95419d556790bc344956addff1c4b00f61a58cab961b0e8bb575a3a2b9dab71ee1246937c75de67c4dce9d706a1f37
6
+ metadata.gz: 35b602aab30776439e94a915b9e769723923c7a1e8aacee8c278ab7b76186696657607e37033791f35f1f152822a0ba76ebdefcefaa8370fd4ed9638a63ef8e4
7
+ data.tar.gz: 411b92a0e28adc7dd629a15309d9916dd5e5bcab94d940970bb076fbae1d20891361931cdbc061a6a9eda2d406b3a57c494460f2b4c57099a462604f3d650968
data/lib/regularity.rb CHANGED
@@ -19,11 +19,12 @@ class Regularity
19
19
 
20
20
  def initialize
21
21
  @str = ''
22
+ @ended = false
22
23
  end
23
24
 
24
25
  def start_with(*args)
25
26
  raise Regularity::Error.new('#start_with? called multiple times') unless @str.empty?
26
- write '^%s' % interpret(*args)
27
+ write '^%s', args
27
28
  end
28
29
 
29
30
  def append(*args)
@@ -32,11 +33,17 @@ class Regularity
32
33
  alias_method :then, :append
33
34
 
34
35
  def end_with(*args)
35
- write '%s$' % interpret(*args)
36
+ write '%s$', args
37
+ @ended = true
38
+ self
36
39
  end
37
40
 
38
41
  def maybe(*args)
39
- write '%s?' % interpret(*args)
42
+ write '%s?', args
43
+ end
44
+
45
+ def not(*args)
46
+ write '(?!%s)', args
40
47
  end
41
48
 
42
49
  def one_of(ary)
@@ -44,17 +51,36 @@ class Regularity
44
51
  end
45
52
 
46
53
  def between(range, pattern)
47
- raise Regularity:Error.new('must provide an array of 2 integers') unless range.length == 2
54
+ unless range.length == 2 && range.any? { |i| i.is_a?(Integer) }
55
+ raise Regularity:Error.new('must provide an array of 2 elements, one of them must be an integer')
56
+ end
57
+
48
58
  write '%s{%s,%s}' % [interpret(pattern), range[0], range[1]]
49
59
  end
50
60
 
61
+ def at_least(times, pattern)
62
+ between [times, nil], pattern
63
+ end
64
+
65
+ def at_most(times, pattern)
66
+ between [nil, times], pattern
67
+ end
68
+
69
+ def zero_or_more(pattern)
70
+ write '%s*', pattern
71
+ end
72
+
73
+ def one_or_more(pattern)
74
+ write '%s+', pattern
75
+ end
76
+
51
77
  def regex
52
78
  Regexp.new(@str)
53
79
  end
54
80
  alias_method :get, :regex
55
81
 
56
82
  def =~(other)
57
- regex.=~(other)
83
+ regex =~ other
58
84
  end
59
85
 
60
86
  def method_missing(meth, *args, &block)
@@ -75,8 +101,9 @@ class Regularity
75
101
 
76
102
  private
77
103
 
78
- def write(str)
79
- @str << str
104
+ def write(str, args=nil)
105
+ raise Regularity::Error.new('#end_with has already been called') if @ended
106
+ @str << (args.nil? ? str : str % interpret(*args))
80
107
  self
81
108
  end
82
109
 
@@ -1,3 +1,3 @@
1
1
  class Regularity
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regularity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Berls
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 2.0.7
56
+ rubygems_version: 2.0.3
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: A friendly regular expression builder for Ruby