Class: Proteus::DefinitionParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition_helper = nil, class_parser = nil, input_parser = nil) ⇒ DefinitionParser


Constructor



36
37
38
39
40
41
42
43
# File 'lib/DefinitionParser.rb', line 36

def initialize( definition_helper = nil, class_parser = nil,
  input_parser = nil )
  
  @definition_helper = definition_helper
  @class_parser = class_parser
  @input_parser = input_parser
  
end

Instance Attribute Details

#class_parserObject

Returns the value of attribute class_parser.



53
54
55
# File 'lib/DefinitionParser.rb', line 53

def class_parser
  @class_parser
end

#definition_helperObject

Returns the value of attribute definition_helper.



53
54
55
# File 'lib/DefinitionParser.rb', line 53

def definition_helper
  @definition_helper
end

#input_parserObject

Returns the value of attribute input_parser.



53
54
55
# File 'lib/DefinitionParser.rb', line 53

def input_parser
  @input_parser
end

Instance Method Details

#parse_yaml(yaml, component_class, current_ns = nil) ⇒ Object

Takes the YAML input read directly from the definition file and parses it, returning the loaded ComponentClass.

yaml: The input YAML to be parsed. component_class: The component class to load.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/DefinitionParser.rb', line 74

def parse_yaml( yaml, component_class, current_ns = nil )
  
  result = component_class || ComponentClass.new
  
  # Let the class parser handle interpreting the YAML, then load the parent
  # class and parse all the values in the children and properties of the new
  # component class.
  
  @class_parser.parse_yaml( yaml, result )
  
  # Get the parent class
  if result.parent != nil
    result.parent = @definition_helper.get_class( result.parent.split(':'),
      current_ns )
  end
  
  # Parse properties
  for property in result.properties
    result.properties[ property[0] ] =
      @input_parser.parse_yaml( property[1], current_ns )
  end
  
  # Parse children
  result.children.length.times do |i|
    result.children[i] = @input_parser.parse_yaml( result.children[i],
      current_ns )
  end
  
  return result
end