Class: PrettyPrint::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/prettyprint.rb

Overview

A node in the print tree that represents plain content that cannot be broken up (by default this assumes strings, but it can really be anything).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeText

Returns a new instance of Text.



234
235
236
237
# File 'lib/syntax_tree/prettyprint.rb', line 234

def initialize
  @objects = []
  @width = 0
end

Instance Attribute Details

#objectsObject (readonly)

Returns the value of attribute objects.



232
233
234
# File 'lib/syntax_tree/prettyprint.rb', line 232

def objects
  @objects
end

#widthObject (readonly)

Returns the value of attribute width.



232
233
234
# File 'lib/syntax_tree/prettyprint.rb', line 232

def width
  @width
end

Instance Method Details

#add(object: "", width: object.length) ⇒ Object



239
240
241
242
# File 'lib/syntax_tree/prettyprint.rb', line 239

def add(object: "", width: object.length)
  @objects << object
  @width += width
end

#pretty_print(q) ⇒ Object



244
245
246
247
248
# File 'lib/syntax_tree/prettyprint.rb', line 244

def pretty_print(q)
  q.group(2, "text([", "])") do
    q.seplist(objects) { |object| q.pp(object) }
  end
end