Class: Kleene::OnlineMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/kleene/naive_online_regex.rb

Overview

A MatchData pair

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#matchObject (readonly)

MatchData



68
69
70
# File 'lib/kleene/naive_online_regex.rb', line 68

def match
  @match
end

#offsetsObject (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

#regexObject (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

#capturesObject



105
106
107
# File 'lib/kleene/naive_online_regex.rb', line 105

def captures
  @match.captures
end

#cloneObject



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

Returns:

  • (Boolean)


89
90
91
# File 'lib/kleene/naive_online_regex.rb', line 89

def eql?(other)
  self == other
end

#hashObject



93
94
95
# File 'lib/kleene/naive_online_regex.rb', line 93

def hash
  identity.hash
end

#identityObject



81
82
83
# File 'lib/kleene/naive_online_regex.rb', line 81

def identity
  [@regex, @offsets, to_a]
end

#to_aObject



97
98
99
# File 'lib/kleene/naive_online_regex.rb', line 97

def to_a
  @match.to_a
end

#to_hObject



101
102
103
# File 'lib/kleene/naive_online_regex.rb', line 101

def to_h
  { @regex => to_a, :offsets => @offsets }
end