class Gyoku::Prettifier

Constants

DEFAULT_COMPACT
DEFAULT_INDENT

Attributes

compact[RW]
indent[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/gyoku/prettifier.rb, line 14
def initialize(options = {})
  @indent = options[:indent] || DEFAULT_INDENT
  @compact = options[:compact].nil? ? DEFAULT_COMPACT : options[:compact]
end
prettify(xml, options = {}) click to toggle source
# File lib/gyoku/prettifier.rb, line 10
def self.prettify(xml, options = {})
  new(options).prettify(xml)
end

Public Instance Methods

prettify(xml) click to toggle source

Adds intendations and newlines to xml to make it more readable

# File lib/gyoku/prettifier.rb, line 20
def prettify(xml)
  result = ''
  formatter = REXML::Formatters::Pretty.new indent
  formatter.compact = compact
  doc = REXML::Document.new xml
  formatter.write doc, result
  result
end