Class: Object

Inherits:
BasicObject
Defined in:
lib/icss/serialization/zaml.rb

Overview

Behavior for custom classes

Instance Method Summary collapse

Instance Method Details

#to_yaml_propertiesObject



191
192
193
# File 'lib/icss/serialization/zaml.rb', line 191

def to_yaml_properties
  instance_variables.sort        # Default YAML behavior
end

#to_zaml(z = ZAML.new) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/icss/serialization/zaml.rb', line 197

def to_zaml(z=ZAML.new)
  z.first_time_only(self) {
    z.emit(zamlized_class_name(Object))
    z.nested {
      instance_variables = to_yaml_properties
      if instance_variables.empty?
        z.emit(" {}")
      else
        instance_variables.each { |v|
          z.nl
          v[1..-1].to_zaml(z)       # Remove leading '@'
          z.emit(': ')
          instance_variable_get(v).to_zaml(z)
        }
      end
    }
  }
end

#zamlized_class_name(root) ⇒ Object



194
195
196
# File 'lib/icss/serialization/zaml.rb', line 194

def zamlized_class_name(root)
  "!ruby/#{root.name.downcase}#{self.class == root ? '' : ":#{self.class.name}"}"
end