Class: Schatter::Command::ListMessages

Inherits:
Object
  • Object
show all
Includes:
Schatter::Colour, Index
Defined in:
lib/schatter/command/list_messages.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

Methods included from Schatter::Colour

#c

Constructor Details

#initialize(conversation) ⇒ ListMessages

Returns a new instance of ListMessages.



10
11
12
13
14
# File 'lib/schatter/command/list_messages.rb', line 10

def initialize conversation
  @conversation = conversation
  @usage = ''
  @help = 'Lists messages for the current conversation'
end

Instance Attribute Details

#conversationObject (readonly)

Returns the value of attribute conversation.



8
9
10
# File 'lib/schatter/command/list_messages.rb', line 8

def conversation
  @conversation
end

#helpObject (readonly)

Returns the value of attribute help.



8
9
10
# File 'lib/schatter/command/list_messages.rb', line 8

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



8
9
10
# File 'lib/schatter/command/list_messages.rb', line 8

def usage
  @usage
end

Instance Method Details

#description(message, index) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/schatter/command/list_messages.rb', line 22

def description message, index
  person = conversation.people[message.person_id]
  parent_index = conversation.messages.keys.index message.parent_id
  email = person ? person.email : '?'
  list = [
    c(to_index(index), :yellow),
    c(message.formatted_timestamp, :blue),
    c(email, :magenta),
    message.content
  ]
  list << c("(reply to #{to_index(parent_index)})", :green) if parent_index
  list.join ' '
end

#execute(*ignored) ⇒ Object



16
17
18
19
20
# File 'lib/schatter/command/list_messages.rb', line 16

def execute *ignored
  conversation.messages(true).values.each_with_index do |message, index|
    puts description message, index
  end
end