Class: Schatter::Command::DeleteMessage

Inherits:
Object
  • Object
show all
Includes:
Index
Defined in:
lib/schatter/command/delete_message.rb

Constant Summary

Constants included from Index

Index::LETTERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Index

#from_index, #to_index

Constructor Details

#initialize(conversation) ⇒ DeleteMessage

Returns a new instance of DeleteMessage.



8
9
10
11
12
# File 'lib/schatter/command/delete_message.rb', line 8

def initialize conversation
  @conversation = conversation
  @usage = '<index>'
  @help = 'Deletes the specified message'
end

Instance Attribute Details

#conversationObject (readonly)

Returns the value of attribute conversation.



6
7
8
# File 'lib/schatter/command/delete_message.rb', line 6

def conversation
  @conversation
end

#helpObject (readonly)

Returns the value of attribute help.



6
7
8
# File 'lib/schatter/command/delete_message.rb', line 6

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



6
7
8
# File 'lib/schatter/command/delete_message.rb', line 6

def usage
  @usage
end

Instance Method Details

#execute(index) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/schatter/command/delete_message.rb', line 14

def execute index
  message = conversation.messages.values[from_index(index)]
  unless message
    puts "invalid index"
    return
  end
  message.destroy
  puts "message #{index} destroyed"
end