Class: RubyUtils::BaseHelpOutput
- Inherits:
-
Object
- Object
- RubyUtils::BaseHelpOutput
- Defined in:
- lib/ruby_utils/base_help_output.rb
Overview
Abstract 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_dual_argument_text(symbol, argument, parameters, text) ⇒ Object
private
method to add a (key, value) pair where the value contains help text with two argument.
-
.add_one_argument_help_entries ⇒ Object
private
method to specify and add the help entries with help text and one argument.
-
.add_simple_text(symbol, argument, text) ⇒ Object
private
method to add a (key, value) pair where the value contains the help text.
-
.add_single_argument_text(symbol, argument, parameter, text) ⇒ Object
private
method to add a (key, value) pair where the value contains help text with one argument.
-
.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.
-
.add_two_argument_help_entries ⇒ Object
private
method to specify and add the help entries with help text and two arguments.
-
.build_entry(parameter, quantity, argument, text) ⇒ String
private
method to build the entry text when dealing with one ore more parameters.
-
.get_script_name ⇒ Object
private
method to set the name of the script project.
-
.initialize_output ⇒ Object
private
method to initialize the hash containing the help entries.
-
.print_configuration_parameter ⇒ Object
private
method to print the available configuration parameter.
-
.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.
-
.print_help_head ⇒ Object
private
method to print the headlines of the general help entry.
-
.print_invalid_combinations ⇒ Object
private
method to print the invalid parameter combinations.
Instance Attribute Details
#parameters ⇒ Hash (readonly, private)
Returns hash which stores available parameters and their help text.
25 26 27 |
# File 'lib/ruby_utils/base_help_output.rb', line 25 def parameters @parameters end |
Class Method Details
.add_dual_argument_text(symbol, argument, parameters, text) ⇒ Object (private)
method to add a (key, value) pair where the value contains help text with two argument
121 122 123 124 |
# File 'lib/ruby_utils/base_help_output.rb', line 121 def self.add_dual_argument_text(symbol, argument, parameters, text) add_text(symbol, build_entry(argument.light_blue, "arguments:", parameters, text)) end |
.add_one_argument_help_entries ⇒ Object (private)
method to specify and add the help entries with help text and one argument
49 50 51 52 53 |
# File 'lib/ruby_utils/base_help_output.rb', line 49 def self.add_one_argument_help_entries fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: add_one_argument_help_entries from its" \ " base class".red end |
.add_simple_text(symbol, argument, text) ⇒ Object (private)
method to add a (key, value) pair where the value contains the help text
99 100 101 |
# File 'lib/ruby_utils/base_help_output.rb', line 99 def self.add_simple_text(symbol, argument, text) add_text(symbol, argument.light_blue.concat(text)) end |
.add_single_argument_text(symbol, argument, parameter, text) ⇒ Object (private)
method to add a (key, value) pair where the value contains help text with one argument
109 110 111 112 |
# File 'lib/ruby_utils/base_help_output.rb', line 109 def self.add_single_argument_text(symbol, argument, parameter, text) add_text(symbol, build_entry(argument.light_blue, "argument:", parameter, text)) end |
.add_single_help_entries ⇒ Object (private)
method to specify and add the help entries with help text only
41 42 43 44 45 46 |
# File 'lib/ruby_utils/base_help_output.rb', line 41 def self.add_single_help_entries fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: add_single_help_entries from its base" \ " class".red end |
.add_text(symbol, text) ⇒ Object (private)
method to add a (key, value) pair to the parameter hash
91 92 93 |
# File 'lib/ruby_utils/base_help_output.rb', line 91 def self.add_text(symbol, text) @parameters[symbol] = text end |
.add_two_argument_help_entries ⇒ Object (private)
method to specify and add the help entries with help text and two arguments
56 57 58 59 60 |
# File 'lib/ruby_utils/base_help_output.rb', line 56 def self.add_two_argument_help_entries fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: add_two_argument_help_entries from its" \ " base class".red end |
.build_entry(parameter, quantity, argument, text) ⇒ String (private)
method to build the entry text when dealing with one ore more parameters
132 133 134 |
# File 'lib/ruby_utils/base_help_output.rb', line 132 def self.build_entry(parameter, quantity, argument, text) parameter + quantity.red + argument.yellow + text end |
.get_script_name ⇒ Object (private)
method to set the name of the script project
83 84 85 86 |
# File 'lib/ruby_utils/base_help_output.rb', line 83 def self.get_script_name fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: get_script_name from its base class".red end |
.initialize_output ⇒ Object (private)
method to initialize the hash containing the help entries
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_utils/base_help_output.rb', line 28 def self.initialize_output @parameters = Hash.new() add_simple_text(:help, " -h, --help ", "show help text") add_simple_text(:version, " -v, --version ", "prints the current version of the project") add_single_argument_text(:file, " -f, --file ", " <file>", "; optional parameter that indicates a filepath to a readable file") add_single_help_entries add_one_argument_help_entries add_two_argument_help_entries end |
.print_configuration_parameter ⇒ Object (private)
method to print the available configuration parameter
76 77 78 79 80 |
# File 'lib/ruby_utils/base_help_output.rb', line 76 def self.print_configuration_parameter fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: print_configuration_parameter from its" \ " base class".red end |
.print_help ⇒ Object (private)
method to print the default help text
137 138 139 140 141 142 143 144 145 |
# File 'lib/ruby_utils/base_help_output.rb', line 137 def self.print_help print_help_head @parameters.each_value { |value| puts value } print_invalid_combinations print_configuration_parameter end |
.print_help_for(parameter) ⇒ Object
method to print the help text for the given parameter
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ruby_utils/base_help_output.rb', line 11 def self.print_help_for(parameter) initialize_output if (@parameters == nil) if (@parameters[parameter]) puts "#{get_script_name} help:".light_yellow + "\n#{@parameters[parameter]}" elsif (parameter) print_help else raise ArgumentError, "help entry for #{parameter} does not exist".red end end |
.print_help_head ⇒ Object (private)
method to print the headlines of the general help entry
63 64 65 66 |
# File 'lib/ruby_utils/base_help_output.rb', line 63 def self.print_help_head fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: print_help_head from its base class".red end |
.print_invalid_combinations ⇒ Object (private)
method to print the invalid parameter combinations
69 70 71 72 73 |
# File 'lib/ruby_utils/base_help_output.rb', line 69 def self.print_invalid_combinations fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: print_invalid_combinations from its" \ " base class".red end |