Class: R2do::Commands::DisplayCategoriesCommand

Inherits:
R2do::Command show all
Defined in:
lib/r2do/commands/display_categories.rb

Instance Attribute Summary

Attributes inherited from R2do::Command

#description, #extended, #short

Instance Method Summary collapse

Methods inherited from R2do::Command

#to_s

Constructor Details

#initialize(state) ⇒ DisplayCategoriesCommand

Returns a new instance of DisplayCategoriesCommand.



21
22
23
24
25
# File 'lib/r2do/commands/display_categories.rb', line 21

def initialize(state)
  super('l', 'list', 'Displays all the categories.')

  @state = state
end

Instance Method Details

#execute(args) ⇒ void

This method returns an undefined value.

Displays all the categories available

Parameters:

  • the arguments passed to the app by the user



31
32
33
34
35
36
37
38
39
40
# File 'lib/r2do/commands/display_categories.rb', line 31

def execute(args)
  if @state.categories.empty?
      UI.status("No categories to display")
  else
    @state.categories.each do |key, value|
      current = (value == @state.current_category && "*") || ' '
      UI.status("#{current} #{value.name}")
    end
  end
end

#help ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/r2do/commands/display_categories.rb', line 42

def help()
  help = "NAME\n r2do \#{@extended}\n\nSYNOPSIS\n 'r2do \#{@extended}' or 'r2do \#{@short}' are equivalent\n\nDESCRIPTION\nThe \#{@extended} lets you Lists all the available categories in the application.\n\nThe current selected category is marked with and asterisk '*'\n\nusage: r2do \#{@extended}\n\ne.g.\n\n  Category 1\n* Category 2\n  Category 3\n\n  EOF\nend\n"