Class: Match
Overview
© 2008 Los Angeles Times
Instance Attribute Summary collapse
-
#end_idx ⇒ Object
Returns the value of attribute end_idx.
-
#keyword ⇒ Object
Returns the value of attribute keyword.
-
#output ⇒ Object
Returns the value of attribute output.
-
#start_idx ⇒ Object
Returns the value of attribute start_idx.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(keyword, start_idx = 0, end_idx = 0, output = nil) ⇒ Match
constructor
A new instance of Match.
- #length ⇒ Object
- #overlap?(other) ⇒ Boolean
Constructor Details
#initialize(keyword, start_idx = 0, end_idx = 0, output = nil) ⇒ Match
Returns a new instance of Match.
8 9 10 11 12 13 |
# File 'lib/match.rb', line 8 def initialize(keyword, start_idx=0, end_idx=0, output=nil) self.keyword = keyword self.start_idx = start_idx self.end_idx = end_idx self.output = output end |
Instance Attribute Details
#end_idx ⇒ Object
Returns the value of attribute end_idx.
6 7 8 |
# File 'lib/match.rb', line 6 def end_idx @end_idx end |
#keyword ⇒ Object
Returns the value of attribute keyword.
6 7 8 |
# File 'lib/match.rb', line 6 def keyword @keyword end |
#output ⇒ Object
Returns the value of attribute output.
6 7 8 |
# File 'lib/match.rb', line 6 def output @output end |
#start_idx ⇒ Object
Returns the value of attribute start_idx.
6 7 8 |
# File 'lib/match.rb', line 6 def start_idx @start_idx end |
Instance Method Details
#<=>(other) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/match.rb', line 15 def <=>(other) retval = start_idx <=> other.start_idx if (retval == 0) end_idx <=> other.end_idx else retval end end |
#length ⇒ Object
34 35 36 |
# File 'lib/match.rb', line 34 def length end_idx - start_idx end |
#overlap?(other) ⇒ Boolean
24 25 26 27 28 29 30 31 32 |
# File 'lib/match.rb', line 24 def overlap?(other) if (start_idx == other.start_idx || end_idx == other.end_idx) return true elsif (start_idx < other.start_idx) return end_idx > other.start_idx elsif (start_idx > other.start_idx) return other.end_idx > start_idx end end |