Class: Iarm::Handle
- Inherits:
-
Object
- Object
- Iarm::Handle
- Defined in:
- lib/iarm/handle.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#timer ⇒ Object
readonly
Returns the value of attribute timer.
-
#touched_at ⇒ Object
readonly
Returns the value of attribute touched_at.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
-
#depart(channel) ⇒ Object
returns a list of channels that we departed.
-
#initialize(name) ⇒ Handle
constructor
A new instance of Handle.
- #join(channel) ⇒ Object
- #next_msg ⇒ Object
- #no_msgs? ⇒ Boolean
- #poke ⇒ Object
- #push_msg(msg) ⇒ Object
- #say(channel, msg) ⇒ Object
- #send_msg(msg) ⇒ Object
- #timed_out? ⇒ Boolean
-
#timeout ⇒ Object
returns list of channels that this handle was a member of.
- #touch ⇒ Object
Constructor Details
Instance Attribute Details
#channels ⇒ Object
Returns the value of attribute channels.
6 7 8 |
# File 'lib/iarm/handle.rb', line 6 def channels @channels end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/iarm/handle.rb', line 5 def created_at @created_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/iarm/handle.rb', line 5 def name @name end |
#timer ⇒ Object (readonly)
Returns the value of attribute timer.
5 6 7 |
# File 'lib/iarm/handle.rb', line 5 def timer @timer end |
#touched_at ⇒ Object (readonly)
Returns the value of attribute touched_at.
5 6 7 |
# File 'lib/iarm/handle.rb', line 5 def touched_at @touched_at end |
#ttl ⇒ Object
Returns the value of attribute ttl.
6 7 8 |
# File 'lib/iarm/handle.rb', line 6 def ttl @ttl end |
Instance Method Details
#depart(channel) ⇒ Object
returns a list of channels that we departed
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/iarm/handle.rb', line 49 def depart(channel) # returns a list of channels that we departed @channels.keys.select do |ch| if channel.nil? || ch == channel ch.members.delete(self) @channels.delete(ch) ch.post(self, Msg::Part.new(ch.name, self.name)) true end end end |
#join(channel) ⇒ Object
60 61 62 63 64 |
# File 'lib/iarm/handle.rb', line 60 def join(channel) @channels[channel] = channel.members[self] = Time.now.to_i send_msg(channel.topic) if channel.topic channel.post(self, Msg::Join.new(channel.name, self.name, @channels[channel])) end |
#next_msg ⇒ Object
23 24 25 |
# File 'lib/iarm/handle.rb', line 23 def next_msg @msg_mutex.synchronize { @msgs.shift } end |
#no_msgs? ⇒ Boolean
31 32 33 |
# File 'lib/iarm/handle.rb', line 31 def no_msgs? @msgs.empty? end |
#poke ⇒ Object
74 75 76 |
# File 'lib/iarm/handle.rb', line 74 def poke @timer.poke end |
#push_msg(msg) ⇒ Object
27 28 29 |
# File 'lib/iarm/handle.rb', line 27 def push_msg(msg) @msg_mutex.synchronize { @msgs << msg } end |
#say(channel, msg) ⇒ Object
78 79 80 |
# File 'lib/iarm/handle.rb', line 78 def say(channel, msg) channel.members.each_key {|member| member.send_msg(msg) } end |
#send_msg(msg) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/iarm/handle.rb', line 66 def send_msg(msg) if(msg.kind_of?(Msg::Topic) || @name != msg.from) #puts "MSG[#{msg.class}] <##{msg.channel}:#{msg.from}> #{@name} : #{msg.data}" self.push_msg(msg) self.poke end end |
#timed_out? ⇒ Boolean
19 20 21 |
# File 'lib/iarm/handle.rb', line 19 def timed_out? (@touched_at + @ttl) < Time.now.to_i end |
#timeout ⇒ Object
returns list of channels that this handle was a member of
39 40 41 42 43 44 45 46 |
# File 'lib/iarm/handle.rb', line 39 def timeout # returns list of channels that this handle was a member of @channels.keys.select do |channel| channel.members.delete(self) channel.post(self, Msg::Timeout.new(channel.name, self.name)) @channels.delete(channel) true end end |
#touch ⇒ Object
35 36 37 |
# File 'lib/iarm/handle.rb', line 35 def touch @touched_at = Time.now.to_i end |