Class: Gyoku::Prettifier
- Inherits:
-
Object
- Object
- Gyoku::Prettifier
- Defined in:
- lib/gyoku/prettifier.rb
Constant Summary collapse
- DEFAULT_INDENT =
2
- DEFAULT_COMPACT =
true
Instance Attribute Summary collapse
-
#compact ⇒ Object
Returns the value of attribute compact.
-
#indent ⇒ Object
Returns the value of attribute indent.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Prettifier
constructor
A new instance of Prettifier.
-
#prettify(xml) ⇒ Object
Adds intendations and newlines to
xml
to make it more readable.
Constructor Details
#initialize(options = {}) ⇒ Prettifier
Returns a new instance of Prettifier.
14 15 16 17 |
# File 'lib/gyoku/prettifier.rb', line 14 def initialize( = {}) @indent = [:indent] || DEFAULT_INDENT @compact = [:compact].nil? ? DEFAULT_COMPACT : [:compact] end |
Instance Attribute Details
#compact ⇒ Object
Returns the value of attribute compact.
8 9 10 |
# File 'lib/gyoku/prettifier.rb', line 8 def compact @compact end |
#indent ⇒ Object
Returns the value of attribute indent.
8 9 10 |
# File 'lib/gyoku/prettifier.rb', line 8 def indent @indent end |
Class Method Details
.prettify(xml, options = {}) ⇒ Object
10 11 12 |
# File 'lib/gyoku/prettifier.rb', line 10 def self.prettify(xml, = {}) new().prettify(xml) end |
Instance Method Details
#prettify(xml) ⇒ Object
Adds intendations and newlines to xml
to make it more readable
20 21 22 23 24 25 26 27 |
# 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 |