Class: Plist::Emit::IndentedString

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of IndentedString.



183
184
185
186
187
# File 'lib/plist/generator.rb', line 183

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

Instance Attribute Details

#indent_stringObject

Returns the value of attribute indent_string.



181
182
183
# File 'lib/plist/generator.rb', line 181

def indent_string
  @indent_string
end

Instance Method Details

#<<(val) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/plist/generator.rb', line 201

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



197
198
199
# File 'lib/plist/generator.rb', line 197

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

#raise_indentObject



193
194
195
# File 'lib/plist/generator.rb', line 193

def raise_indent
  @indent_level += 1
end

#to_sObject



189
190
191
# File 'lib/plist/generator.rb', line 189

def to_s
  return @contents
end