Class: Dialogue::TemplateFactory
- Inherits:
-
Object
- Object
- Dialogue::TemplateFactory
- Includes:
- Singleton
- Defined in:
- lib/dialogue/template_factory.rb
Instance Attribute Summary collapse
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
- #find(name) ⇒ Object
-
#initialize ⇒ TemplateFactory
constructor
A new instance of TemplateFactory.
- #register(template) ⇒ Object
- #registered?(name) ⇒ Boolean
Constructor Details
#initialize ⇒ TemplateFactory
Returns a new instance of TemplateFactory.
9 10 11 |
# File 'lib/dialogue/template_factory.rb', line 9 def initialize @templates = [] end |
Instance Attribute Details
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
7 8 9 |
# File 'lib/dialogue/template_factory.rb', line 7 def templates @templates end |
Instance Method Details
#find(name) ⇒ Object
13 14 15 |
# File 'lib/dialogue/template_factory.rb', line 13 def find(name) templates.find { |template| template.name.to_s == name.to_s } end |
#register(template) ⇒ Object
17 18 19 20 |
# File 'lib/dialogue/template_factory.rb', line 17 def register(template) raise TemplateAlreadyRegisteredError.new(template) if registered?(template.name) templates << template end |
#registered?(name) ⇒ Boolean
22 23 24 |
# File 'lib/dialogue/template_factory.rb', line 22 def registered?(name) !find(name).nil? end |