Class: Bosh::Cli::TaskTracking::SmartWhitespacePrinter
- Defined in:
- lib/cli/task_tracking/smart_whitespace_printer.rb
Constant Summary collapse
- VALID_SEPARATORS =
[:line_around, :line_before, :before, :none].freeze
- SPACE_BETWEEN_LAST_SEP_AND_SEP =
{ [:line_around, :line_around] => "\n\n", [:line_around, :line_before] => "\n\n", [:line_around, :before] => "\n\n", [:line_around, :none] => "\n\n", [:line_before, :line_around] => "\n\n", [:line_before, :line_before] => "\n\n", [:line_before, :before] => "\n", [:line_before, :none] => nil, [:before, :line_around] => "\n\n", [:before, :line_before] => "\n\n", [:before, :before] => "\n", [:before, :none] => nil, [:none, :line_around] => "\n\n", [:none, :line_before] => "\n\n", [:none, :before] => "\n", [:none, :none] => nil, }.freeze
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize ⇒ SmartWhitespacePrinter
constructor
A new instance of SmartWhitespacePrinter.
- #output ⇒ Object
- #print(separator, msg) ⇒ Object
Constructor Details
#initialize ⇒ SmartWhitespacePrinter
Returns a new instance of SmartWhitespacePrinter.
29 30 31 32 |
# File 'lib/cli/task_tracking/smart_whitespace_printer.rb', line 29 def initialize @buffer = StringIO.new @last_sep = :start end |
Instance Method Details
#finish ⇒ Object
50 51 52 53 54 |
# File 'lib/cli/task_tracking/smart_whitespace_printer.rb', line 50 def finish if VALID_SEPARATORS.include?(@last_sep) @buffer.print("\n") end end |
#output ⇒ Object
46 47 48 |
# File 'lib/cli/task_tracking/smart_whitespace_printer.rb', line 46 def output @buffer.string.tap { @buffer.string = '' } end |
#print(separator, msg) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cli/task_tracking/smart_whitespace_printer.rb', line 34 def print(separator, msg) unless VALID_SEPARATORS.include?(separator) raise ArgumentError, "Unknown separator #{separator.inspect}" end space = SPACE_BETWEEN_LAST_SEP_AND_SEP[[@last_sep, separator]] @buffer.print(space) if space @last_sep = separator @buffer.print(msg) end |