Class: Typed::Group
- Inherits:
-
Object
- Object
- Typed::Group
- Defined in:
- lib/typed-matcher/group.rb
Instance Method Summary collapse
-
#initialize(hsh = {}) ⇒ Group
constructor
A new instance of Group.
- #match(str) ⇒ Object
- #register(type, *regexs) ⇒ Object
Constructor Details
#initialize(hsh = {}) ⇒ Group
Returns a new instance of Group.
4 5 6 7 8 9 10 |
# File 'lib/typed-matcher/group.rb', line 4 def initialize(hsh={}) @types = Hash.new {|h,k| h[k]=[]} hsh.each do |type,regexes| register type, *regexes end end |
Instance Method Details
#match(str) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/typed-matcher/group.rb', line 18 def match str @types.each do |type,regexes| regexes.each do |regex| if m = str.match(regex) return Matcher.new(type,m) end end end end |
#register(type, *regexs) ⇒ Object
12 13 14 15 16 |
# File 'lib/typed-matcher/group.rb', line 12 def register type, *regexs regexs.flatten! @types[type] |= regexs end |