Class: Syllabize::Counter
- Inherits:
-
Object
- Object
- Syllabize::Counter
- 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|io|oa|oo|oi|ea|ee|ai|ae|ay/i- Y_AS_VOWEL =
/[^yY][yY]/- RE_VOWEL =
/(^re[aeiou])/i- SUFFIXES =
/(?<=.)(able|ible|al|ial|ed|en|er|est|ful|ic|ing|ion|ing|less|ly|ment|nes|ous)\z/
Instance Attribute Summary collapse
-
#exceptions_file ⇒ Object
Returns the value of attribute exceptions_file.
-
#str ⇒ Object
Returns the value of attribute str.
Instance Method Summary collapse
-
#__dir__ ⇒ Object
for Ruby 1.9.
- #count_syllables ⇒ Object
-
#initialize(str) ⇒ Counter
constructor
A new instance of Counter.
Constructor Details
#initialize(str) ⇒ Counter
Returns a new instance of Counter.
9 10 11 12 13 14 |
# File 'lib/syllabize.rb', line 9 def initialize(str) @str = strip_punctuation(str) handle_non_string_input load_exceptions @syllables = 0 end |
Instance Attribute Details
#exceptions_file ⇒ Object
Returns the value of attribute exceptions_file.
7 8 9 |
# File 'lib/syllabize.rb', line 7 def exceptions_file @exceptions_file end |
#str ⇒ Object
Returns the value of attribute str.
7 8 9 |
# File 'lib/syllabize.rb', line 7 def str @str end |
Instance Method Details
#__dir__ ⇒ Object
for Ruby 1.9
149 150 151 |
# File 'lib/syllabize.rb', line 149 def __dir__ File.dirname(__FILE__) end |
#count_syllables ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/syllabize.rb', line 24 def count_syllables @str = str.to_i.to_words if is_int_in_string_form? return break_into_words if str.split(' ').length > 1 return handle_exceptions if exceptions.keys.include?(str) count_suffixes if str.scan(SUFFIXES).any? @syllables += count_vowels handle_additions handle_subtractions @syllables <= 1 ? 1 : @syllables end |