Class: PrettyPrint::Breakable

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

Overview

A node in the print tree that represents a place in the buffer that the content can be broken onto multiple lines.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(separator = " ", width = separator.length, force: false, indent: true) ⇒ Breakable

Returns a new instance of Breakable.



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/syntax_tree/prettyprint.rb', line 93

def initialize(
  separator = " ",
  width = separator.length,
  force: false,
  indent: true
)
  @separator = separator
  @width = width
  @force = force
  @indent = indent
end

Instance Attribute Details

#separatorObject (readonly)

Returns the value of attribute separator.



91
92
93
# File 'lib/syntax_tree/prettyprint.rb', line 91

def separator
  @separator
end

#widthObject (readonly)

Returns the value of attribute width.



91
92
93
# File 'lib/syntax_tree/prettyprint.rb', line 91

def width
  @width
end

Instance Method Details

#force?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/syntax_tree/prettyprint.rb', line 105

def force?
  @force
end

#indent?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/syntax_tree/prettyprint.rb', line 109

def indent?
  @indent
end

#pretty_print(q) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/syntax_tree/prettyprint.rb', line 113

def pretty_print(q)
  q.text("breakable")

  attributes = [
    ("force=true" if force?),
    ("indent=false" unless indent?)
  ].compact

  if attributes.any?
    q.text("(")
    q.seplist(attributes, -> { q.text(", ") }) do |attribute|
      q.text(attribute)
    end
    q.text(")")
  end
end