Class: Hiptest::Nodes::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



10
11
12
# File 'lib/hiptest-publisher/nodes.rb', line 10

def children
  @children
end

#parentObject

Returns the value of attribute parent.



10
11
12
# File 'lib/hiptest-publisher/nodes.rb', line 10

def parent
  @parent
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
# File 'lib/hiptest-publisher/nodes.rb', line 54

def ==(other)
  other.class == self.class && other.children == @children
end

#each_direct_childrenObject



44
45
46
47
48
49
50
51
52
# File 'lib/hiptest-publisher/nodes.rb', line 44

def each_direct_children
  children.each_value do |child|
    if child.is_a? Hiptest::Nodes::Node
      yield child
    elsif child.is_a? Array
      child.each {|c| yield c if c.is_a? Hiptest::Nodes::Node }
    end
  end
end

#each_sub_nodes(*types, deep: false) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hiptest-publisher/nodes.rb', line 21

def each_sub_nodes(*types, deep: false)
  return to_enum(:each_sub_nodes, *types, deep: deep) unless block_given?
  path = [self]
  parsed_nodes_id = Set.new

  until path.empty?
    current_node = path.shift

    if current_node.is_a?(Node)
      next if parsed_nodes_id.include? current_node.object_id
      parsed_nodes_id << current_node.object_id

      if types.empty? || types.any? {|type| current_node.is_a?(type)}
        yield current_node
        next unless deep
      end
      current_node.children.each_value {|item| path << item}
    elsif current_node.is_a?(Array)
      current_node.each {|item| path << item}
    end
  end
end

#flat_stringObject



72
73
74
75
76
77
# File 'lib/hiptest-publisher/nodes.rb', line 72

def flat_string
  flat_childs = children.map do |key, value|
    "#{key}: #{flatten_child(value)}"
  end.join(", ")
  "<#{self.class.name} [#{flat_childs}]>"
end

#kindObject



66
67
68
69
70
# File 'lib/hiptest-publisher/nodes.rb', line 66

def kind
  node_kinds[self.class] ||= begin
    self.class.name.split('::').last.downcase
  end
end

#pretty_print_instance_variablesObject



13
14
15
# File 'lib/hiptest-publisher/nodes.rb', line 13

def pretty_print_instance_variables
  super - [:@parent] # do not overload pry output
end

#projectObject



58
59
60
61
62
63
64
# File 'lib/hiptest-publisher/nodes.rb', line 58

def project
  project = self
  while project && !project.is_a?(Hiptest::Nodes::Project)
    project = project.parent
  end
  project
end

#render(rendering_context) ⇒ Object



17
18
19
# File 'lib/hiptest-publisher/nodes.rb', line 17

def render(rendering_context)
  return Hiptest::Renderer.render(self, rendering_context)
end