Class: HammerCLIForeman::Output::Formatters::StructuredReferenceFormatter

Inherits:
HammerCLI::Output::Formatters::FieldFormatter
  • Object
show all
Defined in:
lib/hammer_cli_foreman/output/formatters.rb

Instance Method Summary collapse

Instance Method Details

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

Parameters: :display_field_key - key where the formmatter will look for the main field to display, default is :name :details - detail fields to be displayed

example format:
:details => [
  { :label => _('Type'), :key => :provider_friendly_name, :structured_label => _('Type') },
  { :label => _('Id'), :key => :id }
]


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/hammer_cli_foreman/output/formatters.rb', line 66

def format(data, field_params={})
  return  {} if data.nil? || data == ""

  display_field_key = field_params[:display_field_key] || :name

  # TODO: hardcoded name
  formatted = {
    _('Name') => get_value(data, display_field_key)
  }

  details = field_params[:details]
  details = [details] unless details.is_a?(Array)

  details.map do |detail|
    if detail.is_a?(Hash)
      label = detail[:structured_label]
      label = detail[:label].capitalize if !label && detail[:label]
      if label
        formatted[label] = get_value(data, detail[:key])
      end
    end
  end
  formatted
end

#required_featuresObject



54
55
56
# File 'lib/hammer_cli_foreman/output/formatters.rb', line 54

def required_features
  %i[structured]
end