Class: HelpOutput
- Inherits:
-
Object
- Object
- HelpOutput
- Defined in:
- lib/output/help_output.rb
Overview
Output class for help text
Instance Attribute Summary collapse
-
#parameters ⇒ Hash
readonly
private
Hash which stores available parameters and their help text.
Class Method Summary collapse
-
.add_simple_text(symbol, argument, text) ⇒ Object
private
method to add a (key, value) pair where the value contains the help text.
-
.add_single_help_entries ⇒ Object
private
method to specify and add the help entries with help text only.
-
.add_text(symbol, text) ⇒ Object
private
method to add a (key, value) pair to the parameter hash.
-
.initialize_output ⇒ Object
private
method to initialize the hash containing the help entries.
-
.print_help ⇒ Object
private
method to print the default help text.
-
.print_help_for(parameter) ⇒ Object
method to print the help text for the given parameter.
Instance Attribute Details
#parameters ⇒ Hash (readonly, private)
Returns 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
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_entries ⇒ Object (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
43 44 45 |
# File 'lib/output/help_output.rb', line 43 def self.add_text(symbol, text) @parameters[symbol] = text end |
.initialize_output ⇒ Object (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 |
.print_help ⇒ Object (private)
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 |
.print_help_for(parameter) ⇒ Object
method to print the help text for the given parameter
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 |