Class: Pug::KeywordHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/pug/keyword_handler.rb

Overview

Responds to keywords that provide hints to the User

Instance Method Summary collapse

Constructor Details

#initialize(actions) ⇒ KeywordHandler

Returns a new instance of KeywordHandler.

Parameters:



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

Parameters:

  • text (String)

    text to test

Returns:

  • (Boolean)

    if 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

Parameters:

  • text (String)

    text to run command for

Returns:

  • (String, nil)

    output of command or nil



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