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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGQ5YmI1NTlhNGRmNzRmOTc4YzNkZWUzNDJhZGI0OGRlNDQ5NDA1MQ==
4
+ MjkxNTYxMWVlNmQ5NmM1YTZiZDk2ODlhOGQxODFiNWUwNWI5MDRiNQ==
5
5
  data.tar.gz: !binary |-
6
- ODVjNzM2YTUzMDI1YWQ0MDYwYjNmOWY2NWU2MDBhOGExYjZmYTFlNg==
6
+ NzI5ZjkyOWUwYWU2MTMwNGQ2N2FjYWQ2NDZlMTc2MjAxMDlmYThiOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmMzMGI2OWFmNDg5N2I4Yjc3Njc3MmIyYjdmNjcxNTIwOTQxYjI4NjRjMTgx
10
- ZmFjNGJjMWE1NDAwYjM3OGQzNDk5MTE5NzdkMDM0YzkyM2FlMDJhODU4MzJm
11
- ODE4OGIxNTBiNTZmNTlkMzcwN2M4YTY5NGZiYTAwNDhhOTM2MWY=
9
+ NDZlYjk3YmVlNjYwNDk4NjA0Y2VhMDRjNGU4MjBiZDExNDlmMDFmOTRkNDM1
10
+ YzYwMDBiNmM4ZWM2MmM5MzgxNGFiNjAxMWVjNGVlMDgwZTQ4Y2IyNGRjMTdm
11
+ OTE3ODEwNDgzM2UzOTFjMGExYWVjYTk3MzEzNTEyNWUxODM3M2I=
12
12
  data.tar.gz: !binary |-
13
- MjQzZDRlZjA1YWRmOTgxNzlmMWY0MzRmNGNiODIyYzg4MWM3MmY5ZmY5M2Q1
14
- OWQ0M2FiNDlmNDY3YmVlMGIwOTAxM2RiODczYzAwN2RmZWJjMWVlYjAwYjRi
15
- NWUyMzJjOGU5YWQ4Y2FlNzA1ZTA5ZDlhYjc2ZGE2ZWI0NmM0ZmY=
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`. Unforunately, `then` is also reserved, so you must use `find` instead. I'm very open to better name ideas :)
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.2
1
+ 0.1.3
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "verbal_expressions"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Endacott"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verbal_expressions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Endacott