Created
August 21, 2009 22:43
-
-
Save clarkgrubb/172481 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FogFactor | |
class << self | |
def syllable_count(raw_word) | |
word = raw_word.gsub(/[^a-zA-Z]/,'') | |
syllables = word.scan(/[^aeiouy]+y|[^aeiouy]*(ai|au|ea|ee|ei|ie|io|oa|oi|oo|ou|[aeiou])|([^aeiouy]+|y)(ai|au|ea|ee|ei|ie|io|oa|oi|oo|ou|[aeiou])/i) | |
if syllables.size > 1 and word.match(/(e|es)$/) | |
syllables.size - 1 | |
else | |
syllables.size | |
end | |
end | |
def fog_factor(s) | |
words = s.scan(/\S+/) | |
sentences = s.split(/[.!?]+/) | |
trisyllables = words.select { |w| syllable_count(w) > 2 } | |
(words.size.to_f/sentences.size + trisyllables.size.to_f/words.size) * 0.4 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment