Module: Poefy::PoeticForms
- Included in:
- PoefyGen
- Defined in:
- lib/poefy/poetic_forms.rb
Constant Summary collapse
- POETIC_FORMS =
If the token is an array, then a random sample will be used.
{ default: { rhyme: 'a', indent: '0', syllable: '' }, rondeau: { rhyme: 'aabba aabR aabbaR', indent: '', syllable: '' }, villanelle: { rhyme: 'A1bA2 abA1 abA2 abA1 abA2 abA1A2', indent: '010 001 001 001 001 0011', syllable: '' }, ballade: { rhyme: 'ababbcbC ababbcbC ababbcbC bcbC', indent: '', syllable: '' }, ballata: { rhyme: ['AbbaA','AbbaAbbaA','AbbaAbbaAbbaA'], indent: '', syllable: '' }, sonnet: { rhyme: 'ababcdcdefefgg', indent: '', syllable: '' }, petrarchan: { rhyme: ['abbaabbacdecde','abbaabbacdccdc','abbaabbacdcddc', 'abbaabbacddcdd','abbaabbacddece','abbaabbacdcdcd'], indent: ['01100110010010','10001000100100'], syllable: '' }, limerick: { rhyme: 'aabba', indent: '', syllable: '{1:[8],2:[8],3:[4,5],4:[4,5],5:[8]}' }, haiku: { rhyme: 'abc', indent: '', syllable: '[5,7,5]' }, common: { rhyme: 'abcb', indent: '0101', syllable: '[8,6,8,6]' }, ballad: { rhyme: 'abab', indent: '0101', syllable: '[8,6,8,6]' }, double_dactyl: { rhyme: 'abcd efgd', indent: '', syllable: '[6,6,6,4,0,6,6,6,4]', regex: '{7=>/^\S+$/}' } }
Instance Method Summary collapse
-
#acrostic(word) ⇒ Object
Create a regex specification for acrostics.
-
#acrostic_x(word) ⇒ Object
Create a regex specification for acrostics.
Instance Method Details
#acrostic(word) ⇒ Object
Create a regex specification for acrostics.
acrostic('unintelligible')
acrostic('unin tell igib le')
121 122 123 124 125 126 127 |
# File 'lib/poefy/poetic_forms.rb', line 121 def acrostic word output = {} word.split('').each.with_index do |char, i| output[i + 1] = /^[#{char.downcase}]/i if char != ' ' end output end |
#acrostic_x(word) ⇒ Object
Create a regex specification for acrostics. Uses special logic for ‘X’. Match words starting ‘ex’ and then change case to ‘eX’.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/poefy/poetic_forms.rb', line 132 def acrostic_x word regex = {} transform = {} word.split('').each.with_index do |char, i| if char.downcase == 'x' regex[i + 1] = /^ex/i transform[i + 1] = proc do |line| line[0..1] = 'eX' ' ' + line end elsif char != ' ' regex[i + 1] = /^[#{char.downcase}]/i transform[i + 1] = proc do |line| ' ' + line end end end { regex: regex, transform: transform } end |