Class: Fantasy::Room::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/fantasy-irc/rooms.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Factory

Returns a new instance of Factory.



4
5
6
7
8
# File 'lib/fantasy-irc/rooms.rb', line 4

def initialize connection
    puts "Initializing new Room::Factory #{self} with connection #{connection}"
    @data, @data[:rooms] = Hash.new, Hash.new
    @connection = connection
end

Instance Method Details

#allObject



33
34
35
# File 'lib/fantasy-irc/rooms.rb', line 33

def all
    @data[:rooms]
end

#by_name(name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/fantasy-irc/rooms.rb', line 22

def by_name name
    name.downcase!

    if not @data[:rooms][name] then
        raise "Tried to access unknown room \"#{name}\" in Room::Factory \"#{self}\""
        #TODO: log
    end

    @data[:rooms][name]
end

#new(name) ⇒ Object Also known as: create



10
11
12
13
14
15
16
17
18
# File 'lib/fantasy-irc/rooms.rb', line 10

def new name
    name.downcase!

    if not @data[:rooms][name].nil? then
        raise "We already know the room #{name}"
    end

    @data[:rooms][name] = Room.new(name, @connection)
end