Class: Render::Generator
- Inherits:
-
Object
- Object
- Render::Generator
- Defined in:
- lib/render/generator.rb
Class Attribute Summary collapse
-
.instances ⇒ Object
Returns the value of attribute instances.
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
Returns the value of attribute algorithm.
-
#matcher ⇒ Object
Returns the value of attribute matcher.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.create!(type, matcher, algorithm) ⇒ Object
When in non-live mode, e.g.
- .find(type, to_match) ⇒ Object
- .trigger(type, to_match, algorithm_argument = nil) ⇒ Object
Instance Method Summary collapse
-
#initialize(type, matcher, algorithm) ⇒ Generator
constructor
A new instance of Generator.
- #trigger(algorithm_argument = nil) ⇒ Object
Constructor Details
#initialize(type, matcher, algorithm) ⇒ Generator
Returns a new instance of Generator.
40 41 42 43 44 |
# File 'lib/render/generator.rb', line 40 def initialize(type, matcher, algorithm) self.type = type self.matcher = matcher set_algorithm!(algorithm) end |
Class Attribute Details
.instances ⇒ Object
Returns the value of attribute instances.
13 14 15 |
# File 'lib/render/generator.rb', line 13 def instances @instances end |
Instance Attribute Details
#algorithm ⇒ Object
Returns the value of attribute algorithm.
38 39 40 |
# File 'lib/render/generator.rb', line 38 def algorithm @algorithm end |
#matcher ⇒ Object
Returns the value of attribute matcher.
38 39 40 |
# File 'lib/render/generator.rb', line 38 def matcher @matcher end |
#type ⇒ Object
Returns the value of attribute type.
38 39 40 |
# File 'lib/render/generator.rb', line 38 def type @type end |
Class Method Details
.create!(type, matcher, algorithm) ⇒ Object
When in non-live mode, e.g. testing, you can use custom generators to make fake data for a given attribute type and name-matcher.
20 21 22 23 24 |
# File 'lib/render/generator.rb', line 20 def create!(type, matcher, algorithm) generator = new(type, matcher, algorithm) instances.unshift(generator) generator end |
.find(type, to_match) ⇒ Object
31 32 33 34 35 |
# File 'lib/render/generator.rb', line 31 def find(type, to_match) instances.detect do |generator| (generator.type == type) && to_match.match(generator.matcher) end end |
.trigger(type, to_match, algorithm_argument = nil) ⇒ Object
26 27 28 29 |
# File 'lib/render/generator.rb', line 26 def trigger(type, to_match, algorithm_argument = nil) generator = find(type, to_match) generator.trigger(algorithm_argument) end |
Instance Method Details
#trigger(algorithm_argument = nil) ⇒ Object
46 47 48 |
# File 'lib/render/generator.rb', line 46 def trigger(algorithm_argument = nil) algorithm[algorithm_argument] end |