Class: MatchData
- Inherits:
-
Object
- Object
- MatchData
- Defined in:
- lib/epuber/ruby_extensions/match_data.rb
Instance Method Summary collapse
- #line_index ⇒ Fixnum
- #line_number ⇒ Fixnum
- #matched_line ⇒ String
- #matched_string ⇒ String
- #post_match_lines ⇒ Array<String>
- #pre_match_lines ⇒ Array<String>
Instance Method Details
#line_index ⇒ Fixnum
25 26 27 |
# File 'lib/epuber/ruby_extensions/match_data.rb', line 25 def line_index pre_match_lines.length - 1 end |
#line_number ⇒ 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_line ⇒ 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_string ⇒ String
37 38 39 |
# File 'lib/epuber/ruby_extensions/match_data.rb', line 37 def matched_string self[0] end |
#post_match_lines ⇒ 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_lines ⇒ 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 |