Class: Chat

Inherits:
Object
  • Object
show all
Defined in:
lib/model/chat.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chat_number, updated, participants) ⇒ Chat



7
8
9
10
11
# File 'lib/model/chat.rb', line 7

def initialize(chat_number, updated, participants)
  self.chat_number = chat_number
  self.updated = updated
  self.participants = participants
end

Instance Attribute Details

#chat_numberObject

Returns the value of attribute chat_number.



5
6
7
# File 'lib/model/chat.rb', line 5

def chat_number
  @chat_number
end

#participantsObject

Returns the value of attribute participants.



5
6
7
# File 'lib/model/chat.rb', line 5

def participants
  @participants
end

#updatedObject

Returns the value of attribute updated.



5
6
7
# File 'lib/model/chat.rb', line 5

def updated
  @updated
end

Class Method Details

.ascript_chatsObject



21
22
23
# File 'lib/model/chat.rb', line 21

def self.ascript_chats
  Appscript.app("Messages").chats.get()
end

.fetch_allObject



17
18
19
# File 'lib/model/chat.rb', line 17

def self.fetch_all
  ascript_chats.map.with_index(1){ |chat, i| from_ascript_chat(chat, i) }
end

.from_ascript_chat(chat, chat_number) ⇒ Object



25
26
27
# File 'lib/model/chat.rb', line 25

def self.from_ascript_chat(chat, chat_number)
  new(chat_number, chat.updated.get(), participants_from_ascript_chat(chat))
end

.participants_from_ascript_chat(chat) ⇒ Object



29
30
31
32
33
# File 'lib/model/chat.rb', line 29

def self.participants_from_ascript_chat(chat)
  chat.participants.get().map do |participant|
    Participant.from_ascript_participant(participant)
  end
end

Instance Method Details

#to_sObject



13
14
15
# File 'lib/model/chat.rb', line 13

def to_s
  participants.map(&:name).join(", ")
end