Class: Nanaimo::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/nanaimo/writer.rb,
lib/nanaimo/writer/xml.rb

Overview

Transforms native ruby objects or Plist objects into their ASCII Plist string representation.

Direct Known Subclasses

XMLWriter, XcodeProjectWriter

Defined Under Namespace

Classes: XMLWriter

Constant Summary collapse

UTF8 =

The magic comment that denotes a UTF8-encoded plist.

"// !$*UTF8*$!\n".freeze

Instance Method Summary collapse

Constructor Details

#initialize(plist, pretty = true, output = ::String.new) ⇒ Writer

Returns a new instance of Writer.

Parameters:

  • plist (Plist, String, Hash, Array)

    The plist obejct to write

  • pretty (Boolean) (defaults to: true)

    Whether to serialize annotations and add spaces and newlines to make output more legible

  • output (#<<) (defaults to: ::String.new)

    The output stream to write the plist to



17
18
19
20
21
22
23
# File 'lib/nanaimo/writer.rb', line 17

def initialize(plist, pretty = true, output = ::String.new)
  @plist = plist
  @pretty = pretty
  @output = output
  @indent = 0
  @newlines = true
end

Instance Method Details

#writeObject

Writes the plist to the given output.



27
28
29
30
31
# File 'lib/nanaimo/writer.rb', line 27

def write
  write_utf8
  write_object(@plist.root_object)
  write_newline
end