class PCRE2::MatchData

Attributes

regexp[RW]

Public Class Methods

new(regexp, string, pairs) click to toggle source
# File lib/pcre2/matchdata.rb, line 4
def initialize(regexp, string, pairs)
  @regexp = regexp
  @string = string
  @pairs = pairs
end

Public Instance Methods

[](key) click to toggle source
# File lib/pcre2/matchdata.rb, line 10
def [](key)
  if !key.is_a?(Numeric)
    key = regexp.named_captures[key.to_s].first
  end

  if pair = pairs[key]
    string_from_pair(*pair)
  end
end
capture_pairs() click to toggle source
# File lib/pcre2/matchdata.rb, line 24
def capture_pairs
  pairs[1..-1]
end
captures() click to toggle source
# File lib/pcre2/matchdata.rb, line 32
def captures
  to_a[1..-1]
end
end_of_match() click to toggle source
# File lib/pcre2/matchdata.rb, line 52
def end_of_match
  offset(0)[1]
end
length() click to toggle source
# File lib/pcre2/matchdata.rb, line 36
def length
  start_of_match - end_of_match
end
offset(n) click to toggle source
# File lib/pcre2/matchdata.rb, line 20
def offset(n)
  pairs[n]
end
post_match() click to toggle source
# File lib/pcre2/matchdata.rb, line 44
def post_match
  string[end_of_match .. -1]
end
pre_match() click to toggle source
# File lib/pcre2/matchdata.rb, line 40
def pre_match
  string[0 ... start_of_match]
end
start_of_match() click to toggle source
# File lib/pcre2/matchdata.rb, line 48
def start_of_match
  offset(0)[0]
end
to_a() click to toggle source
# File lib/pcre2/matchdata.rb, line 28
def to_a
  @to_a ||= pairs.map { |pair| string_from_pair(*pair) }
end

Private Instance Methods

string_from_pair(start, ending) click to toggle source
# File lib/pcre2/matchdata.rb, line 58
def string_from_pair(start, ending)
  string.slice(start, ending-start)
end