Class: ThreadStack::Call

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Call

Returns a new instance of Call.



8
9
10
11
12
# File 'lib/threadStack.rb', line 8

def initialize(text)
	@text = text
	@children = Array.new
	@count = 1
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



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

def children
  @children
end

#countObject

Returns the value of attribute count.



5
6
7
# File 'lib/threadStack.rb', line 5

def count
  @count
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/threadStack.rb', line 4

def text
  @text
end

Instance Method Details

#children_sortedObject



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

def children_sorted
children.compact.sort { |a,b| b.count <=> a.count}
end

#merge(call) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/threadStack.rb', line 14

def merge(call)
	if call.nil?
		false
	elsif @text == call.text
		@count += 1
		@children.compact!
		if @children.count{ |x| x.merge(call.children[0])} == 0
			@children << call.children[0]
		end
		@children.compact!
		true
	else
		false
	end
end

#text_countObject



30
31
32
# File 'lib/threadStack.rb', line 30

def text_count
	"#{text} (#{count})"
end