Class: HammerCLI::Output::Formatters::MultilineTextFormatter

Inherits:
FieldFormatter
  • Object
show all
Defined in:
lib/hammer_cli/output/formatters.rb

Constant Summary collapse

INDENT =
'    '.freeze
MAX_WIDTH =
120
MIN_WIDTH =
60

Instance Method Summary collapse

Methods inherited from FieldFormatter

inherited, #match?, #tags

Instance Method Details

#format(text, field_params = {}) ⇒ Object



195
196
197
198
199
# File 'lib/hammer_cli/output/formatters.rb', line 195

def format(text, field_params = {})
  width = [[field_params.fetch(:width, 0), MIN_WIDTH].max, MAX_WIDTH].min
  text.to_s.chars.each_slice(width).map(&:join).join("\n")
      .indent_with(INDENT).prepend("\n")
end

#required_featuresObject



189
190
191
192
193
# File 'lib/hammer_cli/output/formatters.rb', line 189

def required_features
  return %i[serialized multiline rich_text] if tags.empty?

  tags.map { |t| HammerCLI::Output::Utils.tag_to_feature(t) }
end