Class: MatchData

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

Instance Method Summary collapse

Instance Method Details

#line_indexFixnum

Returns:

  • (Fixnum)


25
26
27
# File 'lib/epuber/ruby_extensions/match_data.rb', line 25

def line_index
  pre_match_lines.length - 1
end

#line_numberFixnum

Returns:

  • (Fixnum)


17
18
19
20
21
# File 'lib/epuber/ruby_extensions/match_data.rb', line 17

def line_number
  n = pre_match_lines.length
  n += 1 if n == 0 # it can't be zero, this happens only when the match is at the beginning of file or string
  n
end

#matched_lineString

Returns:

  • (String)


31
32
33
# File 'lib/epuber/ruby_extensions/match_data.rb', line 31

def matched_line
  (pre_match_lines.last || '') + matched_string + (post_match_lines.first || '')
end

#matched_stringString

Returns:

  • (String)


37
38
39
# File 'lib/epuber/ruby_extensions/match_data.rb', line 37

def matched_string
  self[0]
end

#post_match_linesArray<String>

Returns:

  • (Array<String>)


11
12
13
# File 'lib/epuber/ruby_extensions/match_data.rb', line 11

def post_match_lines
  @post_match_lines ||= post_match.split(/\r?\n/)
end

#pre_match_linesArray<String>

Returns:

  • (Array<String>)


5
6
7
# File 'lib/epuber/ruby_extensions/match_data.rb', line 5

def pre_match_lines
  @pre_match_lines ||= pre_match.split(/\r?\n/)
end