Class: HammerCLI::Output::Formatters::ListFormatter

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

Constant Summary collapse

INDENT =
"  "

Instance Method Summary collapse

Methods inherited from FieldFormatter

inherited, #match?, #tags

Instance Method Details

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/hammer_cli/output/formatters.rb', line 117

def format(list, field_params={})
  if list.is_a? Array
    separator = field_params.fetch(:separator, ', ')
    new_line = field_params.fetch(:on_new_line, false)

    list = list.join(separator)
    list ="\n#{list.indent_with(INDENT)}" if new_line
    list
  elsif list
    list.to_s
  else
    ""
  end
end

#required_featuresObject



111
112
113
114
115
# File 'lib/hammer_cli/output/formatters.rb', line 111

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

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