Class: Ellen::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/ellen/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/ellen/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/ellen/action.rb', line 7

def options
  @options
end

#patternObject (readonly)

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

Class Method Details

.prefix_pattern(robot_name) ⇒ Object



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

def self.prefix_pattern(robot_name)
  /\A@?#{Regexp.escape(robot_name)}:?\s*/
end

Instance Method Details

#<=>(action) ⇒ Object



34
35
36
# File 'lib/ellen/action.rb', line 34

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

#all?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ellen/action.rb', line 18

def all?
  !!options[:all]
end

#call(handler, message) ⇒ Object



14
15
16
# File 'lib/ellen/action.rb', line 14

def call(handler, message)
  handler.send(name, message) if message.match pattern_with(handler.robot.name)
end

#descriptionObject



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

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

#hidden?Boolean

Returns:

  • (Boolean)


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

def hidden?
  !!options[:hidden]
end

#nameObject



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

def name
  options[:name]
end