Class: Kleene::OnlineMatch
- Inherits:
-
Object
- Object
- Kleene::OnlineMatch
- Defined in:
- lib/kleene/naive_online_regex.rb
Overview
A MatchData pair
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
MatchData.
-
#offsets ⇒ Object
readonly
Array(Int) -> [start, end] # excludes the end offset.
-
#regex ⇒ Object
readonly
Regexp.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](*args) ⇒ Object
- #captures ⇒ Object
- #clone ⇒ Object
- #decrement_offsets(decrement) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #identity ⇒ Object
-
#initialize(regex, match) ⇒ OnlineMatch
constructor
A new instance of OnlineMatch.
- #to_a ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(regex, match) ⇒ OnlineMatch
Returns a new instance of OnlineMatch.
71 72 73 74 75 |
# File 'lib/kleene/naive_online_regex.rb', line 71 def initialize(regex, match) @regex = regex @match = match @offsets = match.offset(0) end |
Instance Attribute Details
#match ⇒ Object (readonly)
MatchData
68 69 70 |
# File 'lib/kleene/naive_online_regex.rb', line 68 def match @match end |
#offsets ⇒ Object (readonly)
Array(Int) -> [start, end] # excludes the end offset
69 70 71 |
# File 'lib/kleene/naive_online_regex.rb', line 69 def offsets @offsets end |
#regex ⇒ Object (readonly)
Regexp
67 68 69 |
# File 'lib/kleene/naive_online_regex.rb', line 67 def regex @regex end |
Instance Method Details
#==(other) ⇒ Object
85 86 87 |
# File 'lib/kleene/naive_online_regex.rb', line 85 def ==(other) identity == other.identity end |
#[](*args) ⇒ Object
109 110 111 |
# File 'lib/kleene/naive_online_regex.rb', line 109 def [](*args) @match.method(:[]).call(*args) end |
#captures ⇒ Object
105 106 107 |
# File 'lib/kleene/naive_online_regex.rb', line 105 def captures @match.captures end |
#clone ⇒ Object
77 78 79 |
# File 'lib/kleene/naive_online_regex.rb', line 77 def clone OnlineMatch.new(@regex, @match) end |
#decrement_offsets(decrement) ⇒ Object
113 114 115 |
# File 'lib/kleene/naive_online_regex.rb', line 113 def decrement_offsets(decrement) @offsets = @offsets.map {|offset| offset - decrement } end |
#eql?(other) ⇒ Boolean
89 90 91 |
# File 'lib/kleene/naive_online_regex.rb', line 89 def eql?(other) self == other end |
#hash ⇒ Object
93 94 95 |
# File 'lib/kleene/naive_online_regex.rb', line 93 def hash identity.hash end |
#identity ⇒ Object
81 82 83 |
# File 'lib/kleene/naive_online_regex.rb', line 81 def identity [@regex, @offsets, to_a] end |
#to_a ⇒ Object
97 98 99 |
# File 'lib/kleene/naive_online_regex.rb', line 97 def to_a @match.to_a end |
#to_h ⇒ Object
101 102 103 |
# File 'lib/kleene/naive_online_regex.rb', line 101 def to_h { @regex => to_a, :offsets => @offsets } end |