Class: Oga::XML::XmlDeclaration
- Inherits:
-
Object
- Object
- Oga::XML::XmlDeclaration
- Defined in:
- lib/oga/xml/xml_declaration.rb
Overview
Class containing information about an XML declaration tag.
Instance Attribute Summary collapse
- #encoding ⇒ String
-
#standalone ⇒ String
Whether or not the document is a standalone document.
- #version ⇒ String
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ XmlDeclaration
constructor
A new instance of XmlDeclaration.
- #inspect ⇒ String
-
#to_xml ⇒ String
Converts the declaration tag to XML.
Constructor Details
#initialize(options = {}) ⇒ XmlDeclaration
Returns a new instance of XmlDeclaration.
24 25 26 27 28 |
# File 'lib/oga/xml/xml_declaration.rb', line 24 def initialize( = {}) @version = [:version] || '1.0' @encoding = [:encoding] || 'UTF-8' @standalone = [:standalone] end |
Instance Attribute Details
#encoding ⇒ String
11 12 13 |
# File 'lib/oga/xml/xml_declaration.rb', line 11 def encoding @encoding end |
#standalone ⇒ String
Whether or not the document is a standalone document.
15 16 17 |
# File 'lib/oga/xml/xml_declaration.rb', line 15 def standalone @standalone end |
#version ⇒ String
8 9 10 |
# File 'lib/oga/xml/xml_declaration.rb', line 8 def version @version end |
Instance Method Details
#inspect ⇒ String
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/oga/xml/xml_declaration.rb', line 50 def inspect segments = [] [:version, :encoding, :standalone].each do |attr| value = send(attr) if value and !value.empty? segments << "#{attr}: #{value.inspect}" end end "XmlDeclaration(#{segments.join(' ')})" end |
#to_xml ⇒ String
Converts the declaration tag to XML.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/oga/xml/xml_declaration.rb', line 35 def to_xml pairs = [] [:version, :encoding, :standalone].each do |getter| value = send(getter) pairs << %Q{#{getter}="#{value}"} if value end "<?xml #{pairs.join(' ')} ?>" end |