From 230fafa2d39fb84dddd042487a145fca00f036b1 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 3 Apr 2014 22:45:40 +0200 Subject: [PATCH] Document should not inherit from Node. A document is not an XML node on itself. If logic has to be shared between the Document and the Node class I'll resort to using mixins for this. --- lib/oga/xml/document.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/oga/xml/document.rb b/lib/oga/xml/document.rb index 159c542..4c35a4a 100644 --- a/lib/oga/xml/document.rb +++ b/lib/oga/xml/document.rb @@ -3,8 +3,19 @@ module Oga ## # Class description # - class Document < Node - attr_accessor :doctype, :xml_declaration + class Document + attr_accessor :children, :doctype, :xml_declaration + + ## + # @param [Hash] options + # + def initialize(options = {}) + options.each do |key, value| + instance_variable_set("@#{key}", value) if respond_to?(key) + end + + @children ||= [] + end def to_xml xml = children.map(&:to_xml).join('')