Class: Ruboty::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/action.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, options = {}) ⇒ Action

Returns a new instance of Action


9
10
11
12
# File 'lib/ruboty/action.rb', line 9

def initialize(pattern, options = {})
  @pattern = pattern
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


7
8
9
# File 'lib/ruboty/action.rb', line 7

def options
  @options
end

#patternObject (readonly)

Returns the value of attribute pattern


7
8
9
# File 'lib/ruboty/action.rb', line 7

def pattern
  @pattern
end

Class Method Details

.prefix_pattern(robot_name) ⇒ Object


3
4
5
# File 'lib/ruboty/action.rb', line 3

def self.prefix_pattern(robot_name)
  /\[email protected]?#{Regexp.escape(robot_name)}:?\s+/
end

Instance Method Details

#<=>(action) ⇒ Object


43
44
45
# File 'lib/ruboty/action.rb', line 43

def <=>(action)
  pattern.to_s <=> action.pattern.to_s
end

#all?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/ruboty/action.rb', line 22

def all?
  !!options[:all]
end

#call(handler, message, options = {}) ⇒ Object


14
15
16
17
18
19
20
# File 'lib/ruboty/action.rb', line 14

def call(handler, message, options = {})
  if !!options[:missing] == missing? && message.match(pattern_with(handler.robot.name))
    !!handler.send(name, message)
  else
    false
  end
end

#descriptionObject


26
27
28
# File 'lib/ruboty/action.rb', line 26

def description
  options[:description] || "(no description)"
end

#hidden?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/ruboty/action.rb', line 30

def hidden?
  !!options[:hidden]
end

#missing?Boolean

Note:

:missing action is called only when any handler doesn't match given message.

Returns:

  • (Boolean)

35
36
37
# File 'lib/ruboty/action.rb', line 35

def missing?
  !!options[:missing]
end

#nameObject


39
40
41
# File 'lib/ruboty/action.rb', line 39

def name
  options[:name]
end