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 +4 -4
- data/lib/regularity.rb +34 -7
- data/lib/regularity/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48cd1ab7ec0e574a8bfac514862124f6c5d3212c
|
4
|
+
data.tar.gz: befa666012c4d5f3c728f21dbeff5be08320551b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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'
|
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$'
|
36
|
+
write '%s$', args
|
37
|
+
@ended = true
|
38
|
+
self
|
36
39
|
end
|
37
40
|
|
38
41
|
def maybe(*args)
|
39
|
-
write '%s?'
|
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
|
-
|
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
|
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
|
-
|
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
|
|
data/lib/regularity/version.rb
CHANGED
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.
|
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.
|
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
|