Class: ThreadStack::Call
- Inherits:
-
Object
- Object
- ThreadStack::Call
- Defined in:
- lib/threadStack.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#count ⇒ Object
Returns the value of attribute count.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #children_sorted ⇒ Object
-
#initialize(text) ⇒ Call
constructor
A new instance of Call.
- #merge(call) ⇒ Object
- #text_count ⇒ Object
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
#children ⇒ Object
Returns the value of attribute children.
6 7 8 |
# File 'lib/threadStack.rb', line 6 def children @children end |
#count ⇒ Object
Returns the value of attribute count.
5 6 7 |
# File 'lib/threadStack.rb', line 5 def count @count end |
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/threadStack.rb', line 4 def text @text end |
Instance Method Details
#children_sorted ⇒ Object
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_count ⇒ Object
30 31 32 |
# File 'lib/threadStack.rb', line 30 def text_count "#{text} - (#{count})" end |