Properly indent doctype/XML decl inspect values.

This commit is contained in:
Yorick Peterse 2014-04-04 11:13:39 +02:00
parent 37a12722cb
commit 13a9228563
3 changed files with 26 additions and 12 deletions

View File

@ -27,14 +27,15 @@ module Oga
def inspect(indent = 0)
class_name = self.class.to_s.split('::').last
spacing = ' ' * indent
return <<-EOF.strip
#{class_name}(
name: #{name.inspect}
type: #{type.inspect}
public_id: #{public_id.inspect}
system_id: #{system_id.inspect}
)
#{spacing} name: #{name.inspect}
#{spacing} type: #{type.inspect}
#{spacing} public_id: #{public_id.inspect}
#{spacing} system_id: #{system_id.inspect}
#{spacing})
EOF
end
end # Doctype

View File

@ -35,10 +35,22 @@ module Oga
class_name = self.class.to_s.split('::').last
child_lines = children.map { |child| child.inspect(4) }.join("\n")
if doctype
dtd = doctype.inspect(2)
else
dtd = doctype.inspect
end
if xml_declaration
decl = xml_declaration.inspect(2)
else
decl = xml_declaration.inspect
end
return <<-EOF.strip
#{class_name}(
doctype: #{doctype.inspect}
xml_declaration: #{xml_declaration.inspect}
doctype: #{dtd}
xml_declaration: #{decl}
children: [
#{child_lines}
])

View File

@ -35,15 +35,16 @@ module Oga
end
def inspect
def inspect(indent = 0)
class_name = self.class.to_s.split('::').last
spacing = ' ' * indent
return <<-EOF.strip
#{class_name}(
version: #{version.inspect}
encoding: #{encoding.inspect}
standalone: #{standalone.inspect}
)
#{spacing} version: #{version.inspect}
#{spacing} encoding: #{encoding.inspect}
#{spacing} standalone: #{standalone.inspect}
#{spacing})
EOF
end
end # XmlDeclaration