class Pug::KeywordHandler

Responds to keywords that provide hints to the User

Public Class Methods

new(actions) click to toggle source

@param actions [Array<Interfaces::Action>]

user provided actions
# 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

Public Instance Methods

keyword?(text) click to toggle source

Determines if a given text is a keyword @param text [String] text to test @return [Boolean] if text is a keyword

# File lib/pug/keyword_handler.rb, line 21
def keyword?(text)
  @keyword_map.include?(text)
end
run_command_for_keyword(keyword) click to toggle source

Runs the command corresponding to text if it is a keyword @param text [String] text to run command for @return [String, nil] output of command or nil

# 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