Module: HaikuGadget
- Defined in:
- lib/haiku_gadget/version.rb,
lib/haiku_gadget/word_type.rb,
lib/haiku_gadget/dictionary.rb,
lib/haiku_gadget/haiku_gadget.rb,
lib/haiku_gadget/line_template.rb,
lib/haiku_gadget/word_template.rb,
lib/haiku_gadget/haiku_template.rb,
lib/haiku_gadget/line_templates.rb,
lib/haiku_gadget/debug_line_template.rb
Defined Under Namespace
Modules: Dictionary, LineTemplates Classes: DebugLineTemplate, HaikuTemplate, LineTemplate, WordTemplate, WordType
Constant Summary collapse
- VERSION =
'1.0.12'
Class Method Summary collapse
- .bottom_line(word_templates = nil) ⇒ Object
-
.haiku(delim = nil, haiku_template = nil) ⇒ Object
returns a haiku as either a single string or an array of strings, based on whether a delimiter was provided.
-
.haiku_lines(haiku_template) ⇒ Object
return haiku as an array of lines (strings).
-
.haiku_string(delim, haiku_template) ⇒ Object
return a single string where the lines are separated by the provided delimiter.
- .middle_line(word_templates = nil) ⇒ Object
-
.random_line(row_index, word_templates = nil) ⇒ Object
return just a single random line.
- .top_line(word_templates = nil) ⇒ Object
Class Method Details
.bottom_line(word_templates = nil) ⇒ Object
38 39 40 |
# File 'lib/haiku_gadget/haiku_gadget.rb', line 38 def self.bottom_line(word_templates = nil) HaikuGadget.random_line(2, word_templates) end |
.haiku(delim = nil, haiku_template = nil) ⇒ Object
returns a haiku as either a single string or an array of strings, based on whether a delimiter was provided
6 7 8 9 10 11 12 13 14 |
# File 'lib/haiku_gadget/haiku_gadget.rb', line 6 def self.haiku(delim = nil, haiku_template = nil) if delim.nil? # no delimiter, return array haiku_lines haiku_template else # use delimiter and return a single string haiku_string delim, haiku_template end end |
.haiku_lines(haiku_template) ⇒ Object
return haiku as an array of lines (strings)
22 23 24 25 26 27 28 |
# File 'lib/haiku_gadget/haiku_gadget.rb', line 22 def self.haiku_lines(haiku_template) if haiku_template.nil? HaikuTemplate.new.generate else haiku_template.generate end end |
.haiku_string(delim, haiku_template) ⇒ Object
return a single string where the lines are separated by the provided delimiter
17 18 19 |
# File 'lib/haiku_gadget/haiku_gadget.rb', line 17 def self.haiku_string(delim, haiku_template) haiku_lines(haiku_template).join delim end |
.middle_line(word_templates = nil) ⇒ Object
34 35 36 |
# File 'lib/haiku_gadget/haiku_gadget.rb', line 34 def self.middle_line(word_templates = nil) HaikuGadget.random_line(1, word_templates) end |
.random_line(row_index, word_templates = nil) ⇒ Object
return just a single random line
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/haiku_gadget/haiku_gadget.rb', line 43 def self.random_line(row_index, word_templates = nil) fail "invalid row_index: #{row_index.to_s}" unless (0..2).include?(row_index) if word_templates.nil? # get a random template defined for the current row word_templates = HaikuTemplate.new.template_matrix[row_index] end # generate a HaikuTemplate object that only contains a single line with the desired template haiku_template = HaikuTemplate.new [word_templates] haiku_template.generate[0] end |
.top_line(word_templates = nil) ⇒ Object
30 31 32 |
# File 'lib/haiku_gadget/haiku_gadget.rb', line 30 def self.top_line(word_templates = nil) HaikuGadget.random_line(0, word_templates) end |