Class: HelpOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/output/help_output.rb

Overview

Output class for help text

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#parametersHash (readonly, private)

Returns hash which stores available parameters and their help text.

Returns:

  • (Hash)

    hash which stores available parameters and their help text



24
25
26
# File 'lib/output/help_output.rb', line 24

def parameters
  @parameters
end

Class Method Details

.add_simple_text(symbol, argument, text) ⇒ Object (private)

method to add a (key, value) pair where the value contains the help text

Parameters:

  • symbol (Symbol)

    the key

  • argument (String)

    the string part containing the argument

  • text (String)

    the string part containing the description text



51
52
53
# File 'lib/output/help_output.rb', line 51

def self.add_simple_text(symbol, argument, text)
  add_text(symbol, argument.light_blue.concat(text))
end

.add_single_help_entriesObject (private)

method to specify and add the help entries with help text only



33
34
35
36
37
38
# File 'lib/output/help_output.rb', line 33

def self.add_single_help_entries
  add_simple_text(:help, " -h, --help     ", "show help text")
  add_simple_text(:version,
                  " -v, --version  ",
                  "prints the current version of the project")
end

.add_text(symbol, text) ⇒ Object (private)

method to add a (key, value) pair to the parameter hash

Parameters:

  • symbol (Symbol)

    the key

  • text (String)

    the value containing a formatted string



43
44
45
# File 'lib/output/help_output.rb', line 43

def self.add_text(symbol, text)
  @parameters[symbol] = text
end

.initialize_outputObject (private)

method to initialize the hash containing the help entries



27
28
29
30
# File 'lib/output/help_output.rb', line 27

def self.initialize_output
  @parameters = Hash.new()
  add_single_help_entries
end

method to print the default help text



56
57
58
59
60
61
62
63
64
65
# File 'lib/output/help_output.rb', line 56

def self.print_help
  puts "script usage:".red + " ruby <script> "
  puts "help usage :".green + "  ruby <script> (-h | --help)"
  puts "\nWorkAccounting help:".light_yellow

  @parameters.each_value { |value|
    puts value
  }

end

method to print the help text for the given parameter

Parameters:

  • parameter (Symbol)

    provided parameter

Raises:

  • (ArgumentError)

    a non existent parameter is provided



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/output/help_output.rb', line 9

def self.print_help_for(parameter)
  initialize_output if (@parameters == nil)
  if (@parameters[parameter])
    puts "WorkAccounting help:".light_yellow + "\n#{@parameters[parameter]}"
  elsif (parameter)
    print_help
  else
    raise ArgumentError,
          " Error: help entry for #{parameter} does not exist".red
  end
end