Class: Codename::Lister::Factory

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/codename/lister/factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFactory

Returns a new instance of Factory.



8
9
10
# File 'lib/codename/lister/factory.rb', line 8

def initialize
  @listers = []
end

Instance Attribute Details

#listersObject (readonly)

Returns the value of attribute listers.



6
7
8
# File 'lib/codename/lister/factory.rb', line 6

def listers
  @listers
end

Instance Method Details

#infoObject

Public: get information of supported name lists

Returns array of array contains name and description of lists



43
44
45
# File 'lib/codename/lister/factory.rb', line 43

def info
  @listers.collect {|l| [l.name, l.description] }
end

#lister(name) ⇒ Object

Public: Find lister by name

name - string, name of the lister

Returns lister class



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/codename/lister/factory.rb', line 27

def lister(name)
  lister_class = @listers.find do |lister|
    lister.name == name
  end
  
  if lister_class
    lister_class
  else
    raise "Cannot find lister '#{name}'"
  end
end

#register(clazz) ⇒ Object

Public: Register a lister

clazz - a lister class to be register

Returns self



17
18
19
20
# File 'lib/codename/lister/factory.rb', line 17

def register(clazz)
  @listers << clazz.instance
  self
end