Class: MList::Thread

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/mlist/thread.rb

Defined Under Namespace

Classes: Node

Instance Method Summary collapse

Instance Method Details

#first?(message) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/mlist/thread.rb', line 8

def first?(message)
  tree_order.first == message
end

#last?(message) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/mlist/thread.rb', line 12

def last?(message)
  tree_order.last == message
end

#next(message) ⇒ Object



16
17
18
19
# File 'lib/mlist/thread.rb', line 16

def next(message)
  i = tree_order.index(message)
  tree_order[i + 1] unless messages.size < i
end

#previous(message) ⇒ Object



21
22
23
24
# File 'lib/mlist/thread.rb', line 21

def previous(message)
  i = tree_order.index(message)
  tree_order[i - 1] if i > 0
end

#subjectObject



26
27
28
# File 'lib/mlist/thread.rb', line 26

def subject
  messages.first.subject
end

#treeObject

Answers a tree of messages.

The nodes of the tree are decorated to act like a linked list, providing pointers to next and previous in the tree.



35
36
37
38
39
# File 'lib/mlist/thread.rb', line 35

def tree
  return nil if messages.size == 0
  build_tree unless @tree
  @tree
end

#tree_orderObject



41
42
43
44
# File 'lib/mlist/thread.rb', line 41

def tree_order
  build_tree unless @tree
  @tree_order
end