Class: PrisonParser::Prison

Inherits:
Node
  • Object
show all
Defined in:
lib/prison_parser/prison.rb

Instance Attribute Summary

Attributes inherited from Node

#allow_inline, #label, #nodes, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#add_property, #allow_inline?, #finished_reading_node, #inspect, #method_missing, #write_nodes, #write_properties

Constructor Details

#initializePrison

Returns a new instance of Prison.



4
5
6
# File 'lib/prison_parser/prison.rb', line 4

def initialize
  super("Prison")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PrisonParser::Node

Class Method Details

.open(filename) ⇒ Object

Open a prison from the file specified



9
10
11
# File 'lib/prison_parser/prison.rb', line 9

def self.open(filename)
  PrisonParser::Utils::Parser.new.load(filename)
end

Instance Method Details

#create_node(node_label) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/prison_parser/prison.rb', line 19

def create_node(node_label)
  if PrisonParser::Models.const_defined?(node_label)
    node = PrisonParser::Models.const_get(node_label).new
    @nodes[node.label] = node
    node
  else
    super
  end
end

#save(filename) ⇒ Object

Save the prison to the specified filename



14
15
16
17
# File 'lib/prison_parser/prison.rb', line 14

def save(filename)
  file = File.open(filename, "w+")
  PrisonParser::Utils::Writer.new(file).write_prison(self)
end