Class: RSyntaxTree::ElementList

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElementList

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

#elementsObject

Returns the value of attribute elements.



14
15
16
# File 'lib/rsyntaxtree/elementlist.rb', line 14

def elements
  @elements
end

#iteratorObject

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_elementsObject



56
57
58
# File 'lib/rsyntaxtree/elementlist.rb', line 56

def get_elements
  @elements
end

#get_firstObject



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_heightObject



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_nextObject



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_hierarchyObject



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