Sha256: 00a743dc5691dc8481ebd91d6e2c52476f0c37964594bef3bdda0b8d010ba473
Contents?: true
Size: 867 Bytes
Versions: 16
Compression:
Stored size: 867 Bytes
Contents
# frozen_string_literal: true module ForwardCalendar class Node 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 def retrieve_content_tag content = self.class.instance_variable_get(:@content) return {} if content.nil? { content.name.to_sym => content } end 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 end end
Version data entries
16 entries across 16 versions & 1 rubygems