Module: Checksyllable

Defined in:
lib/syllable.rb

Class Method Summary collapse

Class Method Details

.runcheck(statement) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/syllable.rb', line 2

def self.runcheck(statement)
  sentence_count = statement.split(/\.|\? |!/).length #sentence count in the input string
  word_count = statement.split.length  #word count in the input string
  syllable_count = syllable_count(statement)
  #Flesch-Kincaid algorithm
#FKRA = Flesch-Kincaid Reading Age 

#ASL = Average Sentence Length (i.e., the number of words divided by thenumber of sentences) 
#ASW = Average number of Syllable per Word (i.e., the number of syllablesdivided by the number of words)

#FKRA = (0.39 x ASL) + (11.8 x ASW) - 15.59
reading_age_rating = (0.39 * (word_count/sentence_count)) + (11.8 * (syllable_count/word_count)) - 15.59

return reading_age_rating
end

.syllable_count(statement) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/syllable.rb', line 18

def self.syllable_count(statement)
statement.downcase!
return 1 if statement.length <= 3
statement.sub!(/(?:[^laeiouy]es|ed|ea|i|e|a|o|aw|oo|a|u|ir|a\'s|es|ee|ar|er|ay|o|y|ough|oy|oor|air|our|ear|ere|[^laeiouy]e)$/, '')
statement.sub!(/^y/, '')
statement.scan(/[aeiouy]{1,2}/).size
end