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)


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

def line_index
  pre_match_lines.length - 1
end

#line_numberFixnum

Returns:

  • (Fixnum)


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

def line_number
  n = pre_match_lines.length
  n += 1 if n.zero? # 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)


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

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

#matched_stringString

Returns:

  • (String)


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

def matched_string
  self[0]
end

#post_match_linesArray<String>

Returns:

  • (Array<String>)


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

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

#pre_match_linesArray<String>

Returns:

  • (Array<String>)


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

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