lib/moxml/declaration.rb in moxml-0.1.0 vs lib/moxml/declaration.rb in moxml-0.1.1

- old
+ new

@@ -1,50 +1,40 @@ -# lib/moxml/declaration.rb +# frozen_string_literal: true + module Moxml class Declaration < Node - def initialize(version_or_native = "1.0", encoding = "UTF-8", standalone = nil) - case version_or_native - when String - super(adapter.create_declaration(nil, version_or_native, encoding, standalone)) - else - super(version_or_native) - end - end + ALLOWED_VERSIONS = ["1.0", "1.1"].freeze + ALLOWED_STANDALONE = %w[yes no].freeze + ALLOWED_ATTRIBUTES = %w[version encoding standalone].freeze def version - adapter.declaration_version(native) + adapter.declaration_attribute(@native, "version") end def version=(new_version) - adapter.set_declaration_version(native, new_version) - self + adapter.validate_declaration_version(new_version) + adapter.set_declaration_attribute(@native, "version", new_version) end def encoding - adapter.declaration_encoding(native) + adapter.declaration_attribute(@native, "encoding") end def encoding=(new_encoding) - adapter.set_declaration_encoding(native, new_encoding) - self + adapter.validate_declaration_encoding(new_encoding) + adapter.set_declaration_attribute(@native, "encoding", new_encoding) end def standalone - adapter.declaration_standalone(native) + adapter.declaration_attribute(@native, "standalone") end def standalone=(new_standalone) - adapter.set_declaration_standalone(native, new_standalone) - self + adapter.validate_declaration_standalone(new_standalone) + adapter.set_declaration_attribute(@native, "standalone", new_standalone) end - def to_xml - adapter.serialize_declaration(native) - end - - private - - def create_native_node - adapter.create_declaration(nil, "1.0", "UTF-8", nil) + def declaration? + true end end end