Class: Rrrex::MatchData

Inherits:
Object
  • Object
show all
Defined in:
lib/rrrex/match_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(atom, match_data) ⇒ MatchData

Returns a new instance of MatchData.



3
4
5
6
# File 'lib/rrrex/match_data.rb', line 3

def initialize( atom, match_data )
  @atom = atom
  @match_data = match_data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



32
33
34
# File 'lib/rrrex/match_data.rb', line 32

def method_missing( name, *args )
  @match_data.send name, *args
end

Instance Method Details

#[](i) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/rrrex/match_data.rb', line 8

def []( i )
  if i.is_a? Symbol
    named_groups[ i ]
  else
    @match_data[ i ]
  end
end

#named_groupsObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rrrex/match_data.rb', line 16

def named_groups
  @named_groups ||=
    begin
      result = {}
      names = @atom.group_names
      names.each_index do |i|
        result[ names[ i ] ] = @match_data[ i + 1 ]
      end
      result
    end
end

#to_aObject



28
29
30
# File 'lib/rrrex/match_data.rb', line 28

def to_a
  @match_data.to_a
end