Class: PrettierPrint::Text
- Inherits:
-
Object
- Object
- PrettierPrint::Text
- Defined in:
- lib/prettier_print.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
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #add(object: "", width: object.length) ⇒ Object
-
#initialize ⇒ Text
constructor
A new instance of Text.
- #pretty_print(q) ⇒ Object
Constructor Details
#initialize ⇒ Text
Returns a new instance of Text.
242 243 244 245 |
# File 'lib/prettier_print.rb', line 242 def initialize @objects = [] @width = 0 end |
Instance Attribute Details
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
240 241 242 |
# File 'lib/prettier_print.rb', line 240 def objects @objects end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
240 241 242 |
# File 'lib/prettier_print.rb', line 240 def width @width end |
Instance Method Details
#add(object: "", width: object.length) ⇒ Object
247 248 249 250 |
# File 'lib/prettier_print.rb', line 247 def add(object: "", width: object.length) @objects << object @width += width end |
#pretty_print(q) ⇒ Object
252 253 254 255 256 |
# File 'lib/prettier_print.rb', line 252 def pretty_print(q) q.group(2, "text([", "])") do q.seplist(objects) { |object| q.pp(object) } end end |