Class: HangoutsJsonParser::Conversation

Inherits:
Object
  • Object
show all
Defined in:
lib/hangouts_json_parser/conversation.rb

Overview

A Hangouts chat

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type, participants, messages) ⇒ Conversation

Returns a new instance of Conversation.



13
14
15
16
17
18
# File 'lib/hangouts_json_parser/conversation.rb', line 13

def initialize id, type, participants, messages
	@id = id
	@type = type
	@participants = participants
	@messages = messages
end

Instance Attribute Details

#idString (readonly)

Returns the chat id.

Returns:

  • (String)

    the chat id



5
6
7
# File 'lib/hangouts_json_parser/conversation.rb', line 5

def id
  @id
end

#messagesArray<Message> (readonly)

Returns the Messages in this chat.

Returns:

  • (Array<Message>)

    the Messages in this chat



11
12
13
# File 'lib/hangouts_json_parser/conversation.rb', line 11

def messages
  @messages
end

#participantsArray<User> (readonly)

Returns the Users that are participating in this chat.

Returns:

  • (Array<User>)

    the Users that are participating in this chat



9
10
11
# File 'lib/hangouts_json_parser/conversation.rb', line 9

def participants
  @participants
end

#typeSymbol (readonly)

Returns the chat type, :group or :private.

Returns:

  • (Symbol)

    the chat type, :group or :private



7
8
9
# File 'lib/hangouts_json_parser/conversation.rb', line 7

def type
  @type
end

Class Method Details

.from_state(state) ⇒ Conversation

Creates a Conversation based on a conversation_state object

Parameters:

  • state (Hash)

    conversation_state

Returns:



23
24
25
26
27
28
# File 'lib/hangouts_json_parser/conversation.rb', line 23

def self.from_state state
	Conversation.new state['conversation']['id']['id'],
		type_from_string(state['conversation']['type']),
		state['conversation']['participant_data'].map(&User.method(:from_participant_data)),
		state['event'].select{ |e| e["event_type"].eql? "REGULAR_CHAT_MESSAGE" }.map(&Message.method(:from_event_data))
end