Module: TheDude

Defined in:
lib/the_dude.rb,
lib/the_dude/dsl.rb,
lib/the_dude/http.rb,
lib/the_dude/config.rb,
lib/the_dude/plugin.rb,
lib/the_dude/command.rb,
lib/the_dude/version.rb,
lib/the_dude/variable.rb,
lib/the_dude/expression.rb

Defined Under Namespace

Classes: Command, Config, Dsl, Expression, Http, Plugin, UndefinedVariableError, Variable

Constant Summary collapse

VERSION =
'0.0.4'

Class Method Summary collapse

Class Method Details

.ask(question) ⇒ Object

Asks the dude a question



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/the_dude.rb', line 20

def ask question
  command = find_command_for question
  return "Wtf? What do you mean #{question}" unless command
  arguments = arguments_for question, command

  # this is a nasty way of dealing with the fact that we get question
  # returned if it exactly matches the command
  arguments = nil if arguments == question

  command.ask *arguments
end

.command(expression) ⇒ TheDude::Command | false

Returns the command registered with the specified question. This should be the expression before it is processed and parsed for variables

Examples:


TheDude::Comand.new(/something :cool/)
TheDude.command(/something :cool) # returns the above command

Parameters:

  • expression (String | Regex)

    A dude command

Returns:



43
44
45
46
# File 'lib/the_dude.rb', line 43

def command expression
  c = commands.select {|c, v| v.expression.expression == expression}
  (c.any?) ? c.first[1] : false
end

.commandsHash

Returns the commands the dude knows about

Returns:

  • (Hash)

    Returns the commands the dude knows about



49
50
51
# File 'lib/the_dude.rb', line 49

def commands
  @commands || {}
end

.complain(something) ⇒ Object

Outputs something using angry-dude-formatting



54
55
56
# File 'lib/the_dude.rb', line 54

def complain something
  puts angry_dude_format something
end

.register_command(command) ⇒ Object

Registers a new command with the dude

Parameters:



66
67
68
69
# File 'lib/the_dude.rb', line 66

def register_command command
  @commands ||= {}
  @commands[command.expression.to_regexp] = command
end

.register_variable(variable) ⇒ Object

Registers a new variable with the dude

Parameters:



74
75
76
77
# File 'lib/the_dude.rb', line 74

def register_variable variable
  @variables ||= {}
  @variables[variable.name] = variable
end

.resetObject

Resets the dude



80
81
82
83
# File 'lib/the_dude.rb', line 80

def reset
  reset_commands
  reset_variables
end

.say(something) ⇒ Object

Outputs something use dude-formatting



86
87
88
# File 'lib/the_dude.rb', line 86

def say something
  puts dude_format something
end

.variablesHash

Returns the variables the dude knows about

Returns:

  • (Hash)

    Returns the variables the dude knows about



59
60
61
# File 'lib/the_dude.rb', line 59

def variables
  @variables || {}
end