Class: HaikuGadget::HaikuTemplate
- Inherits:
-
Object
- Object
- HaikuGadget::HaikuTemplate
- Defined in:
- lib/haiku_gadget/haiku_template.rb
Instance Attribute Summary collapse
-
#template_matrix ⇒ Object
readonly
Returns the value of attribute template_matrix.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(template_matrix = nil) ⇒ HaikuTemplate
constructor
A new instance of HaikuTemplate.
Constructor Details
#initialize(template_matrix = nil) ⇒ HaikuTemplate
Returns a new instance of HaikuTemplate.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/haiku_gadget/haiku_template.rb', line 10 def initialize(template_matrix = nil) # generate a template_matrix randomly if one was not provided if template_matrix.nil? template_matrix = [ HaikuTemplate.random_template(LineTemplates::ALL_TOP_LINES), HaikuTemplate.random_template(LineTemplates::ALL_MIDDLE_LINES), HaikuTemplate.random_template(LineTemplates::ALL_BOTTOM_LINES) ] end # clone the two-dimensional array (so syllable counts can be changed safely) @template_matrix = template_matrix.map { |lt| lt.clone } complete_template end |
Instance Attribute Details
#template_matrix ⇒ Object (readonly)
Returns the value of attribute template_matrix.
8 9 10 |
# File 'lib/haiku_gadget/haiku_template.rb', line 8 def template_matrix @template_matrix end |
Instance Method Details
#generate ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/haiku_gadget/haiku_template.rb', line 24 def generate lines = [] @template_matrix.each do |line_template| words = line_template.real_words lines << words.join(' ') end lines end |