Class: Arugula::MatchData
- Inherits:
-
Object
- Object
- Arugula::MatchData
- Defined in:
- lib/arugula/match_data.rb
Instance Attribute Summary collapse
-
#end_index ⇒ Object
Returns the value of attribute end_index.
-
#start_index ⇒ Object
Returns the value of attribute start_index.
Instance Method Summary collapse
- #add_capture(name, start_index, end_index) ⇒ Object
- #freeze ⇒ Object
-
#initialize(regexp, string) ⇒ MatchData
constructor
A new instance of MatchData.
- #inspect ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(regexp, string) ⇒ MatchData
Returns a new instance of MatchData.
3 4 5 6 7 8 9 |
# File 'lib/arugula/match_data.rb', line 3 def initialize(regexp, string) # require "awesome_print" # ap regexp, raw: true @regexp = regexp @string = string.dup.freeze @captures = Hash[regexp.captures.map { |c| [c.name, nil] }] end |
Instance Attribute Details
#end_index ⇒ Object
Returns the value of attribute end_index.
16 17 18 |
# File 'lib/arugula/match_data.rb', line 16 def end_index @end_index end |
#start_index ⇒ Object
Returns the value of attribute start_index.
15 16 17 |
# File 'lib/arugula/match_data.rb', line 15 def start_index @start_index end |
Instance Method Details
#add_capture(name, start_index, end_index) ⇒ Object
11 12 13 |
# File 'lib/arugula/match_data.rb', line 11 def add_capture(name, start_index, end_index) @captures[name] = start_index...end_index end |
#freeze ⇒ Object
33 34 35 36 |
# File 'lib/arugula/match_data.rb', line 33 def freeze @captures.freeze super end |
#inspect ⇒ Object
22 23 24 25 26 27 |
# File 'lib/arugula/match_data.rb', line 22 def inspect captures_part = @captures.map do |name, range| " #{name}:#{@string[range].dump}" end.join "#<MatchData #{to_s.dump}#{captures_part}>" end |
#to_a ⇒ Object
29 30 31 |
# File 'lib/arugula/match_data.rb', line 29 def to_a @captures.map { |_name, range| @string[range] }.unshift(to_s) end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/arugula/match_data.rb', line 18 def to_s @string[start_index...end_index] end |