Class: GlooLang::Persist::FileSaver

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo_lang/persist/file_saver.rb

Instance Method Summary collapse

Constructor Details

#initialize(engine, pn, obj) ⇒ FileSaver

Set up a file storage for an object.



14
15
16
17
18
19
# File 'lib/gloo_lang/persist/file_saver.rb', line 14

def initialize( engine, pn, obj )
  @engine = engine
  @mech = @engine.platform.getFileMech( @engine )
  @pn = pn
  @obj = obj
end

Instance Method Details

#get_obj(obj, indent = 0) ⇒ Object

Convert an object to textual representation. This is a recursive function.



40
41
42
43
44
45
46
47
# File 'lib/gloo_lang/persist/file_saver.rb', line 40

def get_obj( obj, indent = 0 )
  t = tabs( indent )
  str = "#{t}#{obj.name} [#{obj.type_display}] : #{obj.value_display}\n"
  obj.children.each do |child|
    str << get_obj( child, indent + 1 )
  end
  return str
end

#saveObject

Save the object to the file.



24
25
26
27
# File 'lib/gloo_lang/persist/file_saver.rb', line 24

def save
  data = get_obj( @obj )
  @mech.write( @pn, data )
end

#tabs(indent = 0) ⇒ Object

Get string of tabs for indentation.



32
33
34
# File 'lib/gloo_lang/persist/file_saver.rb', line 32

def tabs( indent = 0 )
  return "\t" * indent
end