Sha256: 5fa043b2ecdd31b5380b5526636763bb9935d53f32eebd188d15b61e31508e04

Contents?: true

Size: 753 Bytes

Versions: 5

Compression:

Stored size: 753 Bytes

Contents

# frozen_string_literal: true

class MatchData
  # @return [Array<String>]
  #
  def pre_match_lines
    @pre_match_lines ||= pre_match.split(/\r?\n/)
  end

  # @return [Array<String>]
  #
  def post_match_lines
    @post_match_lines ||= post_match.split(/\r?\n/)
  end

  # @return [Fixnum]
  #
  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

  # @return [Fixnum]
  #
  def line_index
    pre_match_lines.length - 1
  end

  # @return [String]
  #
  def matched_line
    (pre_match_lines.last || '') + matched_string + (post_match_lines.first || '')
  end

  # @return [String]
  #
  def matched_string
    self[0]
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
epuber-0.7.4 lib/epuber/ruby_extensions/match_data.rb
epuber-0.7.3 lib/epuber/ruby_extensions/match_data.rb
epuber-0.7.2 lib/epuber/ruby_extensions/match_data.rb
epuber-0.7.1 lib/epuber/ruby_extensions/match_data.rb
epuber-0.7.0 lib/epuber/ruby_extensions/match_data.rb