Class: Protobug::Compiler::Builder::Comment

Inherits:
Struct
  • Object
show all
Defined in:
lib/protobug/compiler/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commentObject

Returns the value of attribute comment

Returns:

  • (Object)

    the current value of comment



197
198
199
# File 'lib/protobug/compiler/builder.rb', line 197

def comment
  @comment
end

Instance Method Details

#compact?Boolean

Returns:

  • (Boolean)


219
# File 'lib/protobug/compiler/builder.rb', line 219

def compact? = false

#empty?Boolean

Returns:

  • (Boolean)


218
# File 'lib/protobug/compiler/builder.rb', line 218

def empty? = false

#render(q) ⇒ Object

rubocop:disable Naming/MethodParameterName



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/protobug/compiler/builder.rb', line 198

def render(q) # rubocop:disable Naming/MethodParameterName
  if comment.start_with?("#")
    q.text(comment)
  else
    prefixed = comment.start_with?(" ")

    q.group do
      q.break_parent
      q.seplist(
        comment.chomp.gsub(/^/m, prefixed ? "#" : "# ").tap do |s|
          s.gsub!(/^#\s*$/m, "#")
        end.each_line(chomp: true),
        -> { q.breakable_empty }
      ) do |line|
        q.text line
      end
    end
  end
end