Class: Triphthong::Verse
- Inherits:
-
Struct
- Object
- Struct
- Triphthong::Verse
- Defined in:
- lib/triphthong/verse.rb
Constant Summary collapse
- NonEIVovel =
/a|ä|à|ą|æ|ë|é|ę|o|ö|ó|ô|u|ü|y/
- SyllableVowel =
Regexp.union [ /ae(?=q|re)/, /ae$/, /(?<=et)a(?=i)/, /(?<=t)ai(?=n)/, /(?<!^[nz])au(?!cz|ł|k)/, /(?<=k)au(?=cz|k)/, /(?<!el|ni)eau/, /e(?=usz)/, /^e(?=unu)/, /(?<=f|z)e(?=um)/, /(?<=n)e(?=utr)/, /(?<=ni)e(?=u)/, /e(?=ucz)/, /(?<=s)e(?=ul)/, /eu/, /ey/, /e/, /(?<=^m)ię$/, /(?<=^m)i(?=(#{NonEIVovel}|e|i)$)/, /ii$/, /ille/, /i(?!e(?!nt)|#{NonEIVovel})/, /foi$/, /(?<=n)ou(?=v)/, /(?<=v)ou(?=s)/, /oyce$/, /oy/, /(?<=q)uo/, /uille/, /qui(?!lle)/, NonEIVovel, ]
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#text ⇒ Object
(also: #to_s)
Returns the value of attribute text.
Instance Method Summary collapse
- #has_caesura_after?(number) ⇒ Boolean
- #has_structure?(str) ⇒ Boolean
- #rhyme_pattern ⇒ Object
- #rhymes_with?(other) ⇒ Boolean
- #size ⇒ Object
- #syllable_count ⇒ Object
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source
3 4 5 |
# File 'lib/triphthong/verse.rb', line 3 def source @source end |
#text ⇒ Object Also known as: to_s
Returns the value of attribute text
3 4 5 |
# File 'lib/triphthong/verse.rb', line 3 def text @text end |
Instance Method Details
#has_caesura_after?(number) ⇒ Boolean
29 30 31 32 33 |
# File 'lib/triphthong/verse.rb', line 29 def has_caesura_after? number sum = 0 word_counts.take_while { |c| sum += c; sum < number } sum == number or number.zero? end |
#has_structure?(str) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/triphthong/verse.rb', line 35 def has_structure? str caesura = str.split('+').first.to_i count = str.split('+').map(&:to_i).inject :+ has_caesura_after? caesura and syllable_count == count end |
#rhyme_pattern ⇒ Object
41 42 43 44 |
# File 'lib/triphthong/verse.rb', line 41 def rhyme_pattern all = words.join all[all.rindex(SyllableVowel, all.rindex(SyllableVowel) - 1)..-1] end |
#rhymes_with?(other) ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/triphthong/verse.rb', line 46 def rhymes_with? other return false if rhyme_pattern != other.rhyme_pattern return false if words.last == other.words.last return false if words.last.end_with? other.words.last return false if other.words.last.end_with? words.last true end |
#size ⇒ Object
54 55 56 |
# File 'lib/triphthong/verse.rb', line 54 def size text.size end |
#syllable_count ⇒ Object
58 59 60 |
# File 'lib/triphthong/verse.rb', line 58 def syllable_count word_counts.inject :+ end |