class Deb822::Emitter
Low-level generator for deb822 document
Public Class Methods
new(output)
click to toggle source
# File lib/deb822/emitter.rb, line 6 def initialize(output) @output = output @at_beginning = true @in_paragraph = false end
Public Instance Methods
emit_continuation_line(line)
click to toggle source
# File lib/deb822/emitter.rb, line 51 def emit_continuation_line(line) if /\A(?:\.|\Z)/.match?(line) @output << ' .' << line else @output << ' ' << line end @output << "\n" unless line.end_with?("\n") self end
emit_field(name, value)
click to toggle source
# File lib/deb822/emitter.rb, line 13 def emit_field(name, value) name = Deb822.FieldName(name) if value.respond_to?(:each_line) enum = value.each_line else enum = value.to_s.each_line end if !@at_beginning && !@in_paragraph @output << "\n" end @at_beginning = false @in_paragraph = true @output << name.to_s << ': ' begin line = enum.next @output << line @output << "\n" unless line.end_with?("\n") rescue StopIteration # nop else loop do emit_continuation_line(enum.next) end end self end
emit_fields(pairs)
click to toggle source
# File lib/deb822/emitter.rb, line 45 def emit_fields(pairs) pairs.each_pair do |name, value| emit_field(name, value) end end
start_paragraph()
click to toggle source
# File lib/deb822/emitter.rb, line 61 def start_paragraph @in_paragraph = false self end
Also aliased as: end_paragraph