Class: Dialogue::ConversationFactory
- Inherits:
-
Object
- Object
- Dialogue::ConversationFactory
- Includes:
- Singleton
- Defined in:
- lib/dialogue/conversation_factory.rb
Instance Attribute Summary collapse
-
#conversations ⇒ Object
readonly
Returns the value of attribute conversations.
Instance Method Summary collapse
- #find(user_id, channel_id) ⇒ Object
-
#initialize ⇒ ConversationFactory
constructor
A new instance of ConversationFactory.
- #register(conversation) ⇒ Object
- #registered?(user_id, channel_id) ⇒ Boolean
- #unregister(conversation) ⇒ Object
Constructor Details
#initialize ⇒ ConversationFactory
Returns a new instance of ConversationFactory.
9 10 11 |
# File 'lib/dialogue/conversation_factory.rb', line 9 def initialize @conversations = [] end |
Instance Attribute Details
#conversations ⇒ Object (readonly)
Returns the value of attribute conversations.
7 8 9 |
# File 'lib/dialogue/conversation_factory.rb', line 7 def conversations @conversations end |
Instance Method Details
#find(user_id, channel_id) ⇒ Object
13 14 15 16 17 |
# File 'lib/dialogue/conversation_factory.rb', line 13 def find(user_id, channel_id) conversations.find do |c| c.user_id == user_id && c.channel_id == channel_id end if !user_id.nil? && !channel_id.nil? end |
#register(conversation) ⇒ Object
19 20 21 |
# File 'lib/dialogue/conversation_factory.rb', line 19 def register(conversation) conversations << conversation unless registered?(conversation.user_id, conversation.channel_id) end |
#registered?(user_id, channel_id) ⇒ Boolean
23 24 25 |
# File 'lib/dialogue/conversation_factory.rb', line 23 def registered?(user_id, channel_id) !find(user_id, channel_id).nil? end |
#unregister(conversation) ⇒ Object
27 28 29 |
# File 'lib/dialogue/conversation_factory.rb', line 27 def unregister(conversation) conversations.delete conversation end |