Class: Chat::DotCommand

Inherits:
Object
  • Object
show all
Defined in:
app/models/chat/dot_command.rb,
app/models/chat/dot_command/gif.rb,
app/models/chat/dot_command/shrug.rb,
app/models/chat/dot_command/validator.rb

Defined Under Namespace

Classes: Gif, Shrug, Validator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, text) ⇒ DotCommand

Returns a new instance of DotCommand.



7
8
9
10
# File 'app/models/chat/dot_command.rb', line 7

def initialize(message, text)
  @message = message
  @text = text
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'app/models/chat/dot_command.rb', line 5

def message
  @message
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'app/models/chat/dot_command.rb', line 5

def text
  @text
end

Instance Method Details

#commandObject



12
13
14
# File 'app/models/chat/dot_command.rb', line 12

def command
  @command ||= text[/^\.[a-zA-z]*/]
end

#performObject



16
17
18
19
20
21
22
# File 'app/models/chat/dot_command.rb', line 16

def perform
  return false unless valid?

  ("Chat::DotCommand::" + command[1..-1].classify).constantize.new(
    message, text[/[^\.[a-zA-z]*].*/]&.squish
  ).perform
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/chat/dot_command.rb', line 24

def valid?
  Chat::DotCommand::Validator.new(command).perform
end