Class: PCRE2::MatchData
- Inherits:
-
Object
- Object
- PCRE2::MatchData
- Defined in:
- lib/pcre2/matchdata.rb
Instance Attribute Summary collapse
-
#pairs ⇒ Object
readonly
Returns the value of attribute pairs.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #capture_pairs ⇒ Object
- #captures ⇒ Object
- #end_of_match ⇒ Object
-
#initialize(regexp, string, pairs) ⇒ MatchData
constructor
A new instance of MatchData.
- #length ⇒ Object
- #offset(n) ⇒ Object
- #post_match ⇒ Object
- #pre_match ⇒ Object
- #start_of_match ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(regexp, string, pairs) ⇒ MatchData
Returns a new instance of MatchData.
4 5 6 7 8 |
# File 'lib/pcre2/matchdata.rb', line 4 def initialize(regexp, string, pairs) @regexp = regexp @string = string @pairs = pairs end |
Instance Attribute Details
#pairs ⇒ Object (readonly)
Returns the value of attribute pairs.
2 3 4 |
# File 'lib/pcre2/matchdata.rb', line 2 def pairs @pairs end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
2 3 4 |
# File 'lib/pcre2/matchdata.rb', line 2 def regexp @regexp end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
2 3 4 |
# File 'lib/pcre2/matchdata.rb', line 2 def string @string end |
Instance Method Details
#[](key) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# 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 ⇒ Object
24 25 26 |
# File 'lib/pcre2/matchdata.rb', line 24 def capture_pairs pairs[1..-1] end |
#captures ⇒ Object
32 33 34 |
# File 'lib/pcre2/matchdata.rb', line 32 def captures to_a[1..-1] end |
#end_of_match ⇒ Object
52 53 54 |
# File 'lib/pcre2/matchdata.rb', line 52 def end_of_match offset(0)[1] end |
#length ⇒ Object
36 37 38 |
# File 'lib/pcre2/matchdata.rb', line 36 def length start_of_match - end_of_match end |
#offset(n) ⇒ Object
20 21 22 |
# File 'lib/pcre2/matchdata.rb', line 20 def offset(n) pairs[n] end |
#post_match ⇒ Object
44 45 46 |
# File 'lib/pcre2/matchdata.rb', line 44 def post_match string[end_of_match .. -1] end |
#pre_match ⇒ Object
40 41 42 |
# File 'lib/pcre2/matchdata.rb', line 40 def pre_match string[0 ... start_of_match] end |
#start_of_match ⇒ Object
48 49 50 |
# File 'lib/pcre2/matchdata.rb', line 48 def start_of_match offset(0)[0] end |
#to_a ⇒ Object
28 29 30 |
# File 'lib/pcre2/matchdata.rb', line 28 def to_a @to_a ||= pairs.map { |pair| string_from_pair(*pair) } end |