class HammerCLIForeman::Output::Formatters::StructuredReferenceFormatter
Public Instance Methods
format(data, field_params={})
click to toggle source
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 } ]
# 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
Protected Instance Methods
get_value(data, key)
click to toggle source
# File lib/hammer_cli_foreman/output/formatters.rb, line 92 def get_value(data, key) data[key] || data[key.to_s] end