verbal_expressions 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +17 -1
- data/VERSION +1 -1
- data/lib/verbal_expressions.rb +1 -1
- data/spec/verbal_expressions_spec.rb +38 -0
- data/verbal_expressions.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjkxNTYxMWVlNmQ5NmM1YTZiZDk2ODlhOGQxODFiNWUwNWI5MDRiNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzI5ZjkyOWUwYWU2MTMwNGQ2N2FjYWQ2NDZlMTc2MjAxMDlmYThiOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDZlYjk3YmVlNjYwNDk4NjA0Y2VhMDRjNGU4MjBiZDExNDlmMDFmOTRkNDM1
|
10
|
+
YzYwMDBiNmM4ZWM2MmM5MzgxNGFiNjAxMWVjNGVlMDgwZTQ4Y2IyNGRjMTdm
|
11
|
+
OTE3ODEwNDgzM2UzOTFjMGExYWVjYTk3MzEzNTEyNWUxODM3M2I=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTc3MDg2NTM1ZDE2MGU3ZmVhMDQ5YWY4MDdiYzk5YzZmMjBiMTIzMzc0ZDg3
|
14
|
+
ZGU1YjVhZmVmZDlkYWY0MTEyY2FhYTEyOTUzMmJmMzhiZWM2YTM5ZDI1Y2I4
|
15
|
+
OWM5NjJlZDk2ZTdhNGMyMjg5MTI1ZjYyNTliNTQxZjFlMTQ5NWU=
|
data/README.md
CHANGED
@@ -56,6 +56,22 @@ result = replace_me.gsub( expression, "duck" );
|
|
56
56
|
puts result # Outputs "Replace duck with a duck"
|
57
57
|
```
|
58
58
|
|
59
|
+
### Regex Capturing
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# Grab the number of goals
|
63
|
+
|
64
|
+
tester = VerEx.new do
|
65
|
+
find 'scored '
|
66
|
+
begin_capture 'goals' # Can be named or unnamed
|
67
|
+
word
|
68
|
+
end_capture
|
69
|
+
end
|
70
|
+
|
71
|
+
match = tester.match('Jerry scored 5 goals!')
|
72
|
+
puts match['goals'] # => 5
|
73
|
+
```
|
74
|
+
|
59
75
|
## API documentation
|
60
76
|
|
61
77
|
I haven't added much documentation to this repo yet, but you can find the documentation for the original JavaScript repo on their [wiki](https://github.com/jehna/VerbalExpressions/wiki). Most of the methods have been ported as of v0.1.0 of the JavaScript repo. Just be sure to use the syntax explained above rather than the dot notation :)
|
@@ -66,7 +82,7 @@ Pull requests are warmly welcomed!
|
|
66
82
|
|
67
83
|
## Issues
|
68
84
|
- I haven't yet ported the modifier code because Ruby Regexp handles modifiers a little differently.
|
69
|
-
- Because `or` is reserved in Ruby, `or` is currently aliased to `alternatively`.
|
85
|
+
- Because `or` is reserved in Ruby, `or` is currently aliased to `alternatively`. Unfortunately, `then` is also reserved, so you must use `find` instead. I'm very open to better name ideas :)
|
70
86
|
|
71
87
|
## Thanks!
|
72
88
|
Thank you to @jehna for coming up with the awesome original idea!
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/verbal_expressions.rb
CHANGED
@@ -10,7 +10,7 @@ class VerEx < Regexp
|
|
10
10
|
@source = ""
|
11
11
|
@suffixes = ""
|
12
12
|
@modifiers = "" # TODO: Ruby Regexp option flags
|
13
|
-
@self_before_instance_eval = eval "self"
|
13
|
+
@self_before_instance_eval = eval "self", block.binding
|
14
14
|
instance_eval &block
|
15
15
|
super(@prefixes + @source + @suffixes, @modifiers)
|
16
16
|
end
|
@@ -2,6 +2,44 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe VerEx do
|
4
4
|
|
5
|
+
describe '#capture' do
|
6
|
+
|
7
|
+
describe 'by name' do
|
8
|
+
|
9
|
+
let(:matcher) do
|
10
|
+
VerEx.new do
|
11
|
+
find 'scored '
|
12
|
+
begin_capture 'goals'
|
13
|
+
word
|
14
|
+
end_capture
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'Successfully captures goals by name' do
|
19
|
+
matcher.match('Jerry scored 5 goals!')['goals'].should == '5'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'without name' do
|
25
|
+
|
26
|
+
let(:matcher) do
|
27
|
+
VerEx.new do
|
28
|
+
start_of_line
|
29
|
+
begin_capture
|
30
|
+
word
|
31
|
+
end_capture
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'Successfully captures player by index' do
|
36
|
+
matcher.match('Jerry scored 5 goals!')[1].should == 'Jerry'
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
5
43
|
describe '#find' do
|
6
44
|
|
7
45
|
let(:matcher) do
|
data/verbal_expressions.gemspec
CHANGED