Module: Poefy::PoeticForms

Included in:
Poem
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: '{o:8,e:6}'
  },
  ballad: {
    rhyme:    'abab',
    indent:   '0101',
    syllable: '{o:8,e:6}'
  },
  double_dactyl: {
    rhyme:    'abcd efgd',
    indent:   '',
    syllable: '{0:6, 4m0:4}',
    regex:    '{7: ^\S+$}'
  }
}

Instance Method Summary collapse

Instance Method Details

#acrostic(word) ⇒ Object

Create a regex specification for acrostics.

acrostic('unintelligible')
acrostic('unin tell igib le')


125
126
127
128
129
130
131
# File 'lib/poefy/poetic_forms.rb', line 125

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’.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/poefy/poetic_forms.rb', line 136

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