Sha256: eccd31e7cd069ae17239bb0557bf530adeeaf83ef026a235ce3df475dba7933c
Contents?: true
Size: 1.01 KB
Versions: 9
Compression:
Stored size: 1.01 KB
Contents
# Author:: Eric Crane (mailto:eric.crane@mac.com) # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved. # # Helper class used to save an object to a file.. # module Gloo module Persist class FileSaver # # Set up a file storage for an object. # def initialize( pn, obj ) @pn = pn @obj = obj end # # Save the object to the file. # def save data = get_obj( @obj ) File.write( @pn, data ) end # # Get string of tabs for indentation. # def tabs( indent = 0 ) return "\t" * indent end # # Convert an object to textual representation. # This is a recursive function. # 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 end end end
Version data entries
9 entries across 9 versions & 1 rubygems