Module: PSD::EngineData::DocumentHelpers

Included in:
PSD::EngineData
Defined in:
lib/psd/enginedata/document_helpers.rb

Overview

A collection of helper methods that are used to manipulate the internal data structure while parsing.

Instance Method Summary collapse

Instance Method Details

#reset_nodeObject

Creates a new node



27
28
29
# File 'lib/psd/enginedata/document_helpers.rb', line 27

def reset_node
  @node = Node.new
end

#set_node(node) ⇒ Object

Sets the current active node



22
23
24
# File 'lib/psd/enginedata/document_helpers.rb', line 22

def set_node(node)
  @node = node
end

#set_property(property = nil) ⇒ Object

Sets the current active property



32
33
34
# File 'lib/psd/enginedata/document_helpers.rb', line 32

def set_property(property = nil)
  @property = property
end

#stack_popObject

Pops a property and node from the parsing stack



17
18
19
# File 'lib/psd/enginedata/document_helpers.rb', line 17

def stack_pop
  return @property_stack.pop, @node_stack.pop
end

#stack_push(property = nil, node = nil) ⇒ Object

Pushes a property and node onto the parsing stack.



8
9
10
11
12
13
14
# File 'lib/psd/enginedata/document_helpers.rb', line 8

def stack_push(property = nil, node = nil)
  node = @node if node.nil?
  property = @property if property.nil?

  @node_stack.push node
  @property_stack.push property
end

#update_node(property, node) ⇒ Object

Updates a node with a given property and child node.



37
38
39
40
41
42
43
# File 'lib/psd/enginedata/document_helpers.rb', line 37

def update_node(property, node)
  if node.is_a?(PSD::EngineData::Node)
    node[property] = @node
  elsif node.is_a?(Array)
    node.push @node
  end
end