Class: CeilingCat::Room

Inherits:
Object
  • Object
show all
Defined in:
lib/ceiling_cat/room.rb

Direct Known Subclasses

Campfire::Room, IRC::Room

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Room

Returns a new instance of Room.



5
6
7
# File 'lib/ceiling_cat/room.rb', line 5

def initialize(opts={})
  @connection = opts[:connection]
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



3
4
5
# File 'lib/ceiling_cat/room.rb', line 3

def connection
  @connection
end

#meObject

Returns the value of attribute me.



3
4
5
# File 'lib/ceiling_cat/room.rb', line 3

def me
  @me
end

#roomObject

Returns the value of attribute room.



3
4
5
# File 'lib/ceiling_cat/room.rb', line 3

def room
  @room
end

#users_in_room(type = nil) ⇒ Object

Returns the value of attribute users_in_room.



3
4
5
# File 'lib/ceiling_cat/room.rb', line 3

def users_in_room
  @users_in_room
end

Instance Method Details

#available_commands(show_private = false) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ceiling_cat/room.rb', line 54

def available_commands(show_private=false)
  messages = []
  plugins.each do |plugin|
    if !plugin.commands.empty? && (plugin.public? || show_private)
      messages << "Commands for #{plugin.name}"
      plugin.commands.each do |command|
        messages << "-- #{command[:command]}: #{command[:description]}" if show_private || command[:public]
      end
    end
  end
  messages
end

#configObject



30
31
32
# File 'lib/ceiling_cat/room.rb', line 30

def config
  @connection.config
end

#list_of_users_in_room(type = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/ceiling_cat/room.rb', line 67

def list_of_users_in_room(type=nil)
  users = users_in_room(type)
  if users.size > 1
    last_user = users.pop
    return users.collect{|user| user.name }.join(", ") + " and #{ last_user.name}"
  elsif users.size == 1
    return users.first.name
  end
end

#plugin(name) ⇒ Object



38
39
40
# File 'lib/ceiling_cat/room.rb', line 38

def plugin(name)
  plugins.find{|plugin| plugin.name.downcase == name.to_s.downcase || plugin.class == name}
end

#plugin_descriptions(show_private = false) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ceiling_cat/room.rb', line 46

def plugin_descriptions(show_private=false)
  messages = []
  plugins.each do |plugin|
    messages << "#{plugin.name}: #{plugin.description}" if show_private || plugin.public?
  end
  messages
end

#plugin_installed?(name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ceiling_cat/room.rb', line 34

def plugin_installed?(name)
  !plugin(name).nil?
end

#pluginsObject



26
27
28
# File 'lib/ceiling_cat/room.rb', line 26

def plugins
  @connection.plugins
end

#sayObject



13
14
15
# File 'lib/ceiling_cat/room.rb', line 13

def say
  raise NotImplementedError, "Implement in chat service files!"
end

#storeObject



42
43
44
# File 'lib/ceiling_cat/room.rb', line 42

def store
  @connection.storage
end

#watchObject



9
10
11
# File 'lib/ceiling_cat/room.rb', line 9

def watch
  raise NotImplementedError, "Implement in chat service files!"
end