Class: NoteRangeByClause

Inherits:
ExplanatoryNote show all
Defined in:
app/models/note_range_by_clause.rb

Instance Method Summary collapse

Methods inherited from ExplanatoryNote

#html_note_text

Instance Method Details

#contains_clause?(clause) ⇒ Boolean


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/note_range_by_clause.rb', line 8

def contains_clause? clause
  clause = clause.to_s
  numeric_clause = clause.to_i
  numeric_start = clause_number.to_i
  numeric_end = range_end.to_i
  
  start_in_range = false
  
  #check if the clause is in the middle of the range
  if numeric_clause > numeric_start && numeric_clause < numeric_end
    return true
  end
  
  #check if the clause is at the end of the range
  if clause == range_end
    return true
  end
  
  #check that the start of the range is *not* numeric
  unless numeric_start.to_s == clause_number || clause == clause_number
    range = [clause_number, clause]
    range.sort!
    if range[1] == clause
      start_in_range = true
    end
  end
  
  #check that the start of the range is numeric
  if numeric_start.to_s == clause_number
    #the clause is numeric and greater than the start of the range
    if numeric_clause.to_s == clause && numeric_clause > numeric_start
      start_in_range = true
    elsif numeric_clause.to_s != clause && numeric_clause >= numeric_start
      start_in_range = true
    end
  end
  
  if start_in_range
    #check whether the clause is below the end of the range
    if numeric_clause < numeric_end
      return true
    end
    #check that the end of the range is *not* numeric
    unless numeric_end.to_s == range_end
      range = [range_end, clause]
      range.sort!
      if range[0] == clause
        return true
      end
    end
  end
  false
end