Class: GitlabInternalEventsCli::Helpers::MetricOptions::Option

Inherits:
Struct
  • Object
show all
Includes:
Formatting
Defined in:
lib/gitlab_internal_events_cli/helpers/metric_options.rb

Overview

Formats & structures a single select/multiselect menu item

Constant Summary

Constants included from Formatting

Formatting::DEFAULT_WINDOW_HEIGHT, Formatting::DEFAULT_WINDOW_WIDTH

Instance Method Summary collapse

Methods included from Formatting

#clear_format, #counter, #divider, #format_error, #format_heading, #format_help, #format_info, #format_prefix, #format_prompt, #format_selection, #format_subheader, #format_warning, #progress_bar

Instance Method Details

#disabledObject

Returns the string to include at the end of disabled menu items. Nil if menu item shouldn’t be disabled



243
244
245
246
247
248
249
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 243

def disabled
  if defined
    pastel.bold(format_help('(already defined)'))
  elsif !supported
    pastel.bold(format_help("(#{identifier.value} unavailable)"))
  end
end

#filter_phraseObject

ex) “where label/property is…”



234
235
236
237
238
239
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 234

def filter_phrase
  return unless filter_name
  return 'where filtered' if disabled

  "#{format_info("where #{filter_name}")} is..."
end

#formattedHash

ex) Monthly/Weekly count of unique users who triggered cli_template_included where label/property is… ex) Monthly/Weekly count of unique users who triggered cli_template_included (user unavailable)

Returns:

  • (Hash)

    see #get_metric_options for format



202
203
204
205
206
207
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 202

def formatted
  name = [time_frame_phrase, operator_phrase, filter_phrase].compact.join(' ')
  name = format_help(name) if disabled

  { name: name, disabled: disabled, value: metric }.compact
end

#highlighted_phraseObject

ex) “unique users”



229
230
231
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 229

def highlighted_phrase
  "#{metric.operator.qualifier} #{identifier.plural}"
end

#identifierObject



209
210
211
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 209

def identifier
  metric.identifier
end

#operator_phraseObject

ex) “count of unique users who triggered cli_template_included”



221
222
223
224
225
226
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 221

def operator_phrase
  phrase = "#{metric.operator.description} #{identifier.description % events_name}"
  phrase.gsub!(highlighted_phrase, format_info(highlighted_phrase)) unless disabled

  phrase
end

#time_frame_phraseObject

ex) “Monthly/Weekly”



214
215
216
217
218
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 214

def time_frame_phrase
  phrase = metric.time_frame.description

  disabled ? phrase : format_info(phrase)
end