Class: RSyntaxTree::ElementList
- Inherits:
-
Object
- Object
- RSyntaxTree::ElementList
- Defined in:
- lib/rsyntaxtree/elementlist.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#iterator ⇒ Object
Returns the value of attribute iterator.
Instance Method Summary collapse
- #add(element) ⇒ Object
- #get_child_count(id) ⇒ Object
- #get_children(id) ⇒ Object
- #get_element_width(id) ⇒ Object
- #get_elements ⇒ Object
- #get_first ⇒ Object
- #get_id(id) ⇒ Object
- #get_indent(id) ⇒ Object
- #get_level_height ⇒ Object
- #get_next ⇒ Object
-
#initialize ⇒ ElementList
constructor
A new instance of ElementList.
- #set_element_width(id, width) ⇒ Object
- #set_hierarchy ⇒ Object
- #set_indent(id, indent) ⇒ Object
Constructor Details
#initialize ⇒ ElementList
Returns a new instance of ElementList.
16 17 18 19 |
# File 'lib/rsyntaxtree/elementlist.rb', line 16 def initialize @elements = [] @iterator = -1 # Iterator index (used for get_first / get_next) end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
14 15 16 |
# File 'lib/rsyntaxtree/elementlist.rb', line 14 def elements @elements end |
#iterator ⇒ Object
Returns the value of attribute iterator.
14 15 16 |
# File 'lib/rsyntaxtree/elementlist.rb', line 14 def iterator @iterator end |
Instance Method Details
#add(element) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/rsyntaxtree/elementlist.rb', line 27 def add(element) @elements << element return if element.parent.zero? parent = get_id(element.parent) parent.type = ETYPE_NODE end |
#get_child_count(id) ⇒ Object
60 61 62 |
# File 'lib/rsyntaxtree/elementlist.rb', line 60 def get_child_count(id) get_children(id).length end |
#get_children(id) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/rsyntaxtree/elementlist.rb', line 64 def get_children(id) children = [] @elements.each do |element| children << element.id if element.parent == id end children end |
#get_element_width(id) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/rsyntaxtree/elementlist.rb', line 72 def get_element_width(id) element = get_id(id) return element.width if element -1; end |
#get_elements ⇒ Object
56 57 58 |
# File 'lib/rsyntaxtree/elementlist.rb', line 56 def get_elements @elements end |
#get_first ⇒ Object
35 36 37 38 39 40 |
# File 'lib/rsyntaxtree/elementlist.rb', line 35 def get_first return nil if @elements.length.empty? @iterator = 0 @elements[@iterator] end |
#get_id(id) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/rsyntaxtree/elementlist.rb', line 49 def get_id(id) @elements.each do |element| return element if element.id == id end nil end |
#get_indent(id) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/rsyntaxtree/elementlist.rb', line 84 def get_indent(id) element = get_id(id) return element.indent if element -1 end |
#get_level_height ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/rsyntaxtree/elementlist.rb', line 96 def get_level_height maxlevel = 0 @elements.each do |element| level = element.level maxlevel = level if level > maxlevel end maxlevel + 1 end |
#get_next ⇒ Object
42 43 44 45 46 47 |
# File 'lib/rsyntaxtree/elementlist.rb', line 42 def get_next @iterator += 1 return @elements[@iterator] if @elements[@iterator] nil end |
#set_element_width(id, width) ⇒ Object
79 80 81 82 |
# File 'lib/rsyntaxtree/elementlist.rb', line 79 def set_element_width(id, width) element = get_id(id) element.width = width if element end |
#set_hierarchy ⇒ Object
21 22 23 24 25 |
# File 'lib/rsyntaxtree/elementlist.rb', line 21 def set_hierarchy @elements.each do |e| get_id(e.parent).add_child(e.id) unless e.parent.zero? end end |
#set_indent(id, indent) ⇒ Object
91 92 93 94 |
# File 'lib/rsyntaxtree/elementlist.rb', line 91 def set_indent(id, indent) element = get_id(id) element.indent = indent if element end |