Class: Match

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/match.rb

Overview

© 2008 Los Angeles Times

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idxObject

Returns the value of attribute end_idx.



6
7
8
# File 'lib/match.rb', line 6

def end_idx
  @end_idx
end

#keywordObject

Returns the value of attribute keyword.



6
7
8
# File 'lib/match.rb', line 6

def keyword
  @keyword
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/match.rb', line 6

def output
  @output
end

#start_idxObject

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

#lengthObject



34
35
36
# File 'lib/match.rb', line 34

def length
  end_idx - start_idx
end

#overlap?(other) ⇒ Boolean

Returns:

  • (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