class ForwardCalendar::Node

Public Instance Methods

to_hash() click to toggle source
# File lib/forward_calendar/node.rb, line 5
def to_hash
  hash = {}
  attributes = self.class.instance_variable_get(:@attributes)
  elements = self.class.instance_variable_get(:@elements)
  content = retrieve_content_tag
  (attributes.to_a + elements.to_a + content.to_a).each do |k, _|
    value = send(k)
    hash[k] = serialize_attribute(value)
  end
  hash
end

Private Instance Methods

retrieve_content_tag() click to toggle source
# File lib/forward_calendar/node.rb, line 19
def retrieve_content_tag
  content = self.class.instance_variable_get(:@content)
  return {} if content.nil?
  { content.name.to_sym => content }
end
serialize_attribute(attribute) click to toggle source
# File lib/forward_calendar/node.rb, line 25
def serialize_attribute(attribute)
  if attribute.is_a?(Array)
    attribute.map { |a| serialize_attribute(a) }
  elsif attribute.respond_to?(:to_hash)
    attribute.to_hash
  else
    attribute
  end
end