Class: Pug::KeywordHandler
- Inherits:
-
Object
- Object
- Pug::KeywordHandler
- Defined in:
- lib/pug/keyword_handler.rb
Overview
Responds to keywords that provide hints to the User
Instance Method Summary collapse
-
#initialize(actions) ⇒ KeywordHandler
constructor
A new instance of KeywordHandler.
-
#keyword?(text) ⇒ Boolean
Determines if a given text is a keyword.
-
#run_command_for_keyword(keyword) ⇒ String?
Runs the command corresponding to text if it is a keyword.
Constructor Details
#initialize(actions) ⇒ KeywordHandler
Returns a new instance of KeywordHandler.
10 11 12 13 14 15 16 |
# File 'lib/pug/keyword_handler.rb', line 10 def initialize(actions) list_action = ListAction.new(actions) @keyword_map = { 'help' => HelpAction.new([list_action]), 'list' => list_action } end |
Instance Method Details
#keyword?(text) ⇒ Boolean
Determines if a given text is a keyword
21 22 23 |
# File 'lib/pug/keyword_handler.rb', line 21 def keyword?(text) @keyword_map.include?(text) end |
#run_command_for_keyword(keyword) ⇒ String?
Runs the command corresponding to text if it is a keyword
29 30 31 32 33 |
# File 'lib/pug/keyword_handler.rb', line 29 def run_command_for_keyword(keyword) return nil unless keyword?(keyword) command = @keyword_map[keyword] command.execute end |