Class: Plist::Emit::IndentedString

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/vendor/plist/lib/plist/generator.rb

Overview

:nodoc:

Constant Summary collapse

@@indent_level =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = "\t") ⇒ IndentedString

Returns a new instance of IndentedString.



171
172
173
174
# File 'lib/puppet/vendor/plist/lib/plist/generator.rb', line 171

def initialize(str = "\t")
  @indent_string = str
  @contents = ''
end

Instance Attribute Details

#indent_stringObject

Returns the value of attribute indent_string.



167
168
169
# File 'lib/puppet/vendor/plist/lib/plist/generator.rb', line 167

def indent_string
  @indent_string
end

Instance Method Details

#<<(val) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/puppet/vendor/plist/lib/plist/generator.rb', line 188

def <<(val)
  if val.is_a? Array
    val.each do |f|
      self << f
    end
  else
    # if it's already indented, don't bother indenting further
    unless val =~ /\A#{@indent_string}/
      indent = @indent_string * @@indent_level

      @contents << val.gsub(/^/, indent)
    else
      @contents << val
    end

    # it already has a newline, don't add another
    @contents << "\n" unless val =~ /\n$/
  end
end

#lower_indentObject



184
185
186
# File 'lib/puppet/vendor/plist/lib/plist/generator.rb', line 184

def lower_indent
  @@indent_level -= 1 if @@indent_level > 0
end

#raise_indentObject



180
181
182
# File 'lib/puppet/vendor/plist/lib/plist/generator.rb', line 180

def raise_indent
  @@indent_level += 1
end

#to_sObject



176
177
178
# File 'lib/puppet/vendor/plist/lib/plist/generator.rb', line 176

def to_s
  return @contents
end