Class: Fantasy::User::Factory
- Inherits:
-
Object
- Object
- Fantasy::User::Factory
- Defined in:
- lib/fantasy-irc/users.rb
Instance Method Summary collapse
- #by_name(name) ⇒ Object
-
#initialize(connection) ⇒ Factory
constructor
A new instance of Factory.
- #new(name) ⇒ Object (also: #create)
Constructor Details
#initialize(connection) ⇒ Factory
Returns a new instance of Factory.
4 5 6 7 8 |
# File 'lib/fantasy-irc/users.rb', line 4 def initialize connection puts "Initializing new User::Factory #{self} with connection #{connection}" @data, @data[:users] = Hash.new, Hash.new @connection = connection end |
Instance Method Details
#by_name(name) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/fantasy-irc/users.rb', line 25 def by_name name name.downcase! if not @data[:users][name] then raise "Tried to access unknown user \"#{name}\" in User::Factory \"#{self}\"" end @data[:users][name] end |
#new(name) ⇒ Object Also known as: create
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fantasy-irc/users.rb', line 10 def new name name = name.split(/!/, 2)[0] # remove mask name_lc = name.downcase if not @data[:users][name_lc].nil? then return @data[:users][name_lc] # TODO: log! not raise # raise "We already know the user #{name}" end @data[:users][name_lc] = User.new(name, @connection) end |