Class: Pug::Action::Enumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/pug/action/enumerator.rb

Overview

Formats actions to an enumerated text representation

Instance Method Summary collapse

Instance Method Details

#grouped_names(actions, group_size = 2) ⇒ Array<Array<String>>

Note:

This does not support descriptions at the moment

Enumerates and groups Action names into a 2D array

Parameters:

  • actions (Array<Interfaces::Action>)

    Action names to enumerate

  • group_size (Integer) (defaults to: 2)

    optional count indicating subarray size

Returns:

  • (Array<Array<String>>)

    enumerated and grouped names



27
28
29
30
# File 'lib/pug/action/enumerator.rb', line 27

def grouped_names(actions, group_size = 2)
  return [] if group_size <= 0
  names(actions).each_slice(group_size).to_a
end

#names(actions, show_description = false) ⇒ Array<String>

Enumerates Action names with an optional description

Parameters:

  • actions (Array<Interfaces::Action>)

    Action names to enumerate

  • show_description (Boolean) (defaults to: false)

    optional flag that adds descriptions

Returns:

  • (Array<String>)

    enumerated names with optional description



11
12
13
14
15
16
17
18
19
20
# File 'lib/pug/action/enumerator.rb', line 11

def names(actions, show_description = false)
  return [] if actions.nil?
  actions.each_with_index.map do |action, index|
    if show_description && !action.description.to_s.empty?
      "#{index}: #{action.name} # #{action.description}"
    else
      "#{index}: #{action.name}"
    end
  end
end