Class: CLI::UI::Prompt::OptionsHandler
- Inherits:
-
Object
- Object
- CLI::UI::Prompt::OptionsHandler
- Defined in:
- lib/cli/ui/prompt/options_handler.rb
Overview
A class that handles the various options of an InteractivePrompt and their callbacks
Instance Method Summary collapse
-
#call(options) ⇒ Object
: ((Array | String) options) -> String.
-
#initialize ⇒ OptionsHandler
constructor
: -> void.
-
#option(option, &handler) ⇒ Object
: (String option) { (String option) -> String } -> void.
-
#options ⇒ Object
: -> Array.
Constructor Details
#initialize ⇒ OptionsHandler
: -> void
10 11 12 |
# File 'lib/cli/ui/prompt/options_handler.rb', line 10 def initialize @options = {} end |
Instance Method Details
#call(options) ⇒ Object
: ((Array | String) options) -> String
25 26 27 28 29 30 31 32 |
# File 'lib/cli/ui/prompt/options_handler.rb', line 25 def call() case when Array .map { |option| @options[option].call() } else @options[].call() end end |
#option(option, &handler) ⇒ Object
: (String option) { (String option) -> String } -> void
20 21 22 |
# File 'lib/cli/ui/prompt/options_handler.rb', line 20 def option(option, &handler) @options[option] = handler end |
#options ⇒ Object
: -> Array
15 16 17 |
# File 'lib/cli/ui/prompt/options_handler.rb', line 15 def @options.keys end |