Class: Syllabize::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/syllabize.rb

Constant Summary collapse

CONSONANTS =
/[bcdfghjklmnpqrstvwxz]/i
VOWELS =
/[aeiou]/i
LE_VOWEL_SOUND =
/((le)\z)|((le(d|r|s))|(ling)\z)/i
DIPHTHONGS =
/ou|ie|oo|oi|ea|ee|ai|ae|ay/i
Y_AS_VOWEL =
/[^yY][yY]/
RE_VOWEL =
/(^re[aeiou])/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word) ⇒ Counter

Returns a new instance of Counter.



8
9
10
11
12
# File 'lib/syllabize.rb', line 8

def initialize(word)
  @word = strip_punctuation(word)
  handle_non_string_input
  load_exceptions
end

Instance Attribute Details

#exceptions_fileObject

Returns the value of attribute exceptions_file.



6
7
8
# File 'lib/syllabize.rb', line 6

def exceptions_file
  @exceptions_file
end

#wordObject

Returns the value of attribute word.



6
7
8
# File 'lib/syllabize.rb', line 6

def word
  @word
end

Instance Method Details

#__dir__Object

for Ruby 1.9



32
33
34
# File 'lib/syllabize.rb', line 32

def __dir__
  File.dirname(__FILE__)
end

#count_syllablesObject



21
22
23
24
25
26
27
# File 'lib/syllabize.rb', line 21

def count_syllables
  return handle_exceptions if exceptions.keys.include?(word)
  @syllables = count_vowels
  handle_additions
  handle_subtractions
  @syllables <= 1 ? 1 : @syllables
end