Class: Codename::Lister::Factory
- Inherits:
-
Object
- Object
- Codename::Lister::Factory
- Includes:
- Singleton
- Defined in:
- lib/codename/lister/factory.rb
Instance Attribute Summary collapse
-
#listers ⇒ Object
readonly
Returns the value of attribute listers.
Instance Method Summary collapse
-
#info ⇒ Object
Public: get information of supported name lists.
-
#initialize ⇒ Factory
constructor
A new instance of Factory.
-
#lister(name) ⇒ Object
Public: Find lister by name.
-
#register(clazz) ⇒ Object
Public: Register a lister.
Constructor Details
#initialize ⇒ Factory
Returns a new instance of Factory.
8 9 10 |
# File 'lib/codename/lister/factory.rb', line 8 def initialize @listers = [] end |
Instance Attribute Details
#listers ⇒ Object (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
#info ⇒ Object
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 |