Class: Triphthong::Verse

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



3
4
5
# File 'lib/triphthong/verse.rb', line 3

def source
  @source
end

#textObject Also known as: to_s

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



3
4
5
# File 'lib/triphthong/verse.rb', line 3

def text
  @text
end

Instance Method Details

#has_caesura_after?(number) ⇒ Boolean

Returns:

  • (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

Returns:

  • (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_patternObject



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

Returns:

  • (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

#sizeObject



54
55
56
# File 'lib/triphthong/verse.rb', line 54

def size
  text.size
end

#syllable_countObject



58
59
60
# File 'lib/triphthong/verse.rb', line 58

def syllable_count
  word_counts.inject :+
end