change name

This commit is contained in:
Torsten Ruger
2017-09-27 15:35:55 +03:00
parent bf1b3e95bd
commit 6ca249118c
23 changed files with 93 additions and 96 deletions

View File

@ -2,49 +2,49 @@
# if you want some attributes not written also check volotile
require_relative "sof/util"
require_relative "sof/node"
require_relative "sof/simple_node"
require_relative "sof/object_node"
require_relative "sof/members"
require_relative "sof/volotile"
require_relative "sof/writer"
require_relative "sof/array_node"
require_relative "sof/hash_node"
require_relative "sof/occurence"
require_relative "rx-file/util"
require_relative "rx-file/node"
require_relative "rx-file/simple_node"
require_relative "rx-file/object_node"
require_relative "rx-file/members"
require_relative "rx-file/volotile"
require_relative "rx-file/writer"
require_relative "rx-file/array_node"
require_relative "rx-file/hash_node"
require_relative "rx-file/occurence"
Class.class_eval do
def to_sof
def to_rxf
self.name
end
end
Symbol.class_eval do
def to_sof()
def to_rxf()
":#{to_s}"
end
end
TrueClass.class_eval do
def to_sof()
def to_rxf()
"true"
end
end
NilClass.class_eval do
def to_sof()
def to_rxf()
"nil"
end
end
FalseClass.class_eval do
def to_sof()
def to_rxf()
"false"
end
end
String.class_eval do
def to_sof()
def to_rxf()
"'" + self + "'"
end
end
Fixnum.class_eval do
def to_sof()
def to_rxf()
to_s
end
end

View File

@ -1,8 +1,8 @@
module Sof
module RxFile
# A ArrayNode is a Node for an Array. See Node for when and how nodes are used in Sof.
# A ArrayNode is a Node for an Array. See Node for when and how nodes are used in RxFile.
# A ArrayNode has a list of children that hold the value node representations for
# the arrays values.
#

View File

@ -1,5 +1,5 @@
module Sof
# A HashNode is a Node for a Hash. See Node for when and how nodes are used in Sof.
module RxFile
# A HashNode is a Node for a Hash. See Node for when and how nodes are used in RxFile.
# A HashNode has a list of children that hold the key/value node representations for
# the hashes keys and values.

View File

@ -1,4 +1,4 @@
module Sof
module RxFile
# Members are members of the graph to be written
# The class collects all reachable objects into a hash for further transformation
@ -37,8 +37,8 @@ module Sof
unless occurence.referenced
# puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 23
# puts "referencing #{@counter} #{occurence.object.name}, at level #{level}/#{occurence.level} " if @counter == 19
if object.respond_to? :sof_reference_name
reference = object.sof_reference_name
if object.respond_to? :rxf_reference_name
reference = object.rxf_reference_name
reference = reference.to_s.gsub(/\s|\W/ , "") #remove space and stuff
if( @references.include?(reference) or reference.empty?)
reference = "#{reference}-#{@counter}"

View File

@ -1,6 +1,6 @@
# We transform objects into a tree of nodes
module Sof
module RxFile
# Before writing the objects are transformed into a tree of nodes.
# as the Members (all objects) are a graph (not tree) this is achieved by referencing

View File

@ -1,5 +1,5 @@
module Sof
module RxFile
# ObjectNode means node with structure
# ie arrays and hashes get transformed into these too, as well as objects with attributes

View File

@ -1,4 +1,4 @@
module Sof
module RxFile
# simple struct like class to wrap an object and hold additionally
# - the shallowest level at which it was seen

View File

@ -1,4 +1,4 @@
module Sof
module RxFile
# What makes a node simple is that it has no further structure
#

View File

@ -1,4 +1,4 @@
module Sof
module RxFile
# module for a couple of helpers that are needed in Members and Writer
@ -24,7 +24,7 @@ module Sof
# attributes may be supressed with Volotile
# TODO should be able to specify order too
def attributes_for object
Sof::Util.attributes(object)
RxFile::Util.attributes(object)
end
# return a list of attributes for a given object

View File

@ -1,4 +1,4 @@
module Sof
module RxFile
# Volotile module keeps track of attributes that are not menat to be written
# The idea being similar to private methods. So not every little detail is relevant
@ -9,7 +9,7 @@ module Sof
module Volotile
@@mapping = { }
# Add attributes that are then ommited from the sof writing process
# Add attributes that are then ommited from the rxf writing process
# The clazz is the real class object (eg String), and thus the
# adding must happen after the class definition, often at the end of the file
# attributes are an array of Symbols

View File

@ -1,6 +1,6 @@
module Sof
module RxFile
# this function writes the object (and all reachable objects) out as sof
# this function writes the object (and all reachable objects) out as rxf
# and returns a string
# For trees or graphs this works best by handing roots
# Internally this is done in three steps:
@ -23,9 +23,9 @@ module Sof
end
# main function, creates nodes from the occurences and writes the nodes to a string
# returns the sof formatted string for all objects
# returns the rxf formatted string for all objects
def write
node = to_sof_node(@members.root , 0)
node = to_rxf_node(@members.root , 0)
io = StringIO.new
node.out( io , 0 )
io.string
@ -36,10 +36,10 @@ module Sof
# from the object we get the Occurence and decide wether a reference node is needed
# simple objects (with more inner structure) become SimpleNodes
# Any structured object becomes a ObjectNode
# Hash and Array create their own nodes via to_sof_node functions on the classes
def to_sof_node(object , level)
# Hash and Array create their own nodes via to_rxf_node functions on the classes
def to_rxf_node(object , level)
if is_value?(object)
return SimpleNode.new(object.to_sof())
return SimpleNode.new(object.to_rxf())
end
occurence = @members.objects[object.object_id]
raise "no object #{object}" unless occurence
@ -57,14 +57,14 @@ module Sof
ref = occurence.referenced
case object.class.name
when "Array" , "Parfait::List"
# If a class defines to_sof_node it tells the write that it will generate Nodes itself
# this delegates to array_to_sof_node
array_to_sof_node(object , level , ref )
# If a class defines to_rxf_node it tells the write that it will generate Nodes itself
# this delegates to array_to_rxf_node
array_to_rxf_node(object , level , ref )
when "Hash" , "Parfait::Dictionary"
# and hash keys/values
hash_to_sof_node( object , level , ref)
hash_to_rxf_node( object , level , ref)
else
object_to_sof_node(object , level , ref)
object_to_rxf_node(object , level , ref)
end
end
@ -76,41 +76,41 @@ module Sof
#
# objects may be derived from array/hash. In that case the ObjectNode gets a super
# (either ArrayNode or HashNode)
def object_to_sof_node( object , level , ref)
def object_to_rxf_node( object , level , ref)
node = ObjectNode.new(object.class.name , ref)
attributes_for(object).each() do |a|
val = get_value(object , a)
next if val.nil?
node.add( a , to_sof_node( val , level + 1) )
node.add( a , to_rxf_node( val , level + 1) )
end
#TODO get all superclsses here, but this covers 99% so . . moving on
superclasses = [object.class.superclass.name]
if superclasses.include?( "Array") or superclasses.include?( "Parfait::List")
node.add_super( array_to_sof_node(object , level , ref ) )
node.add_super( array_to_rxf_node(object , level , ref ) )
end
if superclasses.include?( "Hash") or superclasses.include?( "Parfait::Dictionary")
node.add_super( hash_to_sof_node(object , level , ref ) )
node.add_super( hash_to_rxf_node(object , level , ref ) )
end
node
end
# Creates a ArrayNode (see there) for the Array.
# This mainly involves creating nodes for the children
def array_to_sof_node(array , level , ref )
node = Sof::ArrayNode.new(ref)
def array_to_rxf_node(array , level , ref )
node = RxFile::ArrayNode.new(ref)
array.each do |object|
node.add to_sof_node( object , level + 1)
node.add to_rxf_node( object , level + 1)
end
node
end
# Creates a HashNode (see there) for the Hash.
# This mainly involves creating nodes for key value pairs
def hash_to_sof_node(hash , level , ref)
node = Sof::HashNode.new(ref)
def hash_to_rxf_node(hash , level , ref)
node = RxFile::HashNode.new(ref)
hash.each do |key , object|
k = to_sof_node( key ,level + 1)
v = to_sof_node( object ,level + 1)
k = to_rxf_node( key ,level + 1)
v = to_rxf_node( object ,level + 1)
node.add(k , v)
end
node