Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix readme

  • Loading branch information...
commit 41b41ed04a1f59cecfdb11458fc8eb7705737471 1 parent 0bce372
Peter Schröder authored
Showing with 18 additions and 6 deletions.
  1. +9 −2 lib/rebuil.rb
  2. +3 −3 readme.textile
  3. +6 −1 test/test_rebuil.rb
View
11 lib/rebuil.rb
@@ -14,9 +14,12 @@ class Expression
def initialize
@exp = ""
@options = []
+ @keys = []
+ @matches = {}
end
- def group(expression="", &block)
+ def group(expression="", key=nil, &block)
+ @keys << key
@exp << "("
apply_params expression, &block
@exp << ")"
@@ -76,7 +79,11 @@ def =~(obj)
end
def match(str)
- to_r.match str
+ @matches = to_r.match(str) and self
+ end
+
+ def [](key)
+ @matches[@keys.index(key) + 1]
end
private
View
6 readme.textile
@@ -1,4 +1,4 @@
-h1. rebuil - A Regular Expression Builder
+h1. Rebuil - A Regular Expression Builder
p. A readable DSL for Ruby "Regexp":http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html#UJ.
@@ -6,10 +6,10 @@ h2. Usage
bc.. match = rebuil("hello world") do
many
- group("rebuil")
+ group("rebuil", :cool)
end.match('hello world with rebuil')
-puts "#{match[1]} is cool"
+puts "#{match[:cool]} is cool" #=> rebuil is cool
h2. Examples
View
7 test/test_rebuil.rb
@@ -37,7 +37,12 @@ def test_group_with_characters_matches
exp = re.group{|exp| exp.characters("a")}
assert_match(exp, "anna")
end
-
+
+ def test_group_with_match
+ exp = rebuil.many.group('rebuil', :cool_name)
+ assert_equal(exp.match('hello world with rebuil')[:cool_name], 'rebuil')
+ end
+
def test_rebuil_method
assert_match(rebuil("uschi") << "sushi", "uschisushi")
end
Please sign in to comment.
Something went wrong with that request. Please try again.