class GunningFog

Public Instance Methods

calc_score(avg_words, percent_with_three) click to toggle source
# File lib/odyssey/formulas/gunning_fog.rb, line 27
def calc_score(avg_words, percent_with_three)
  ((avg_words + percent_with_three) * 0.4).round(1)
end
name() click to toggle source
# File lib/odyssey/formulas/gunning_fog.rb, line 31
def name
  'Gunning-Fog Score'
end
score(text, stats) click to toggle source
# File lib/odyssey/formulas/gunning_fog.rb, line 3
def score(text, stats)
  percent = three_syllables(stats['word_count'], text['syllables'])
  calc_score(stats['average_words_per_sentence'], percent)
end
score_per_sentence(text, stats_split) click to toggle source
# File lib/odyssey/formulas/gunning_fog.rb, line 8
def score_per_sentence(text, stats_split)
  res = []
  for i in 0..text['sentences'].length-1
    percent = three_syllables(stats_split['word_count'][i],
                              text['syllables_by_sentence'][i])
    res.push(calc_score(stats_split['word_count'][i], percent))
  end
  res
end
three_syllables(word_count, syllables) click to toggle source

percentage of words with three syllables

# File lib/odyssey/formulas/gunning_fog.rb, line 19
def three_syllables(word_count, syllables)
  with_three = 0
  syllables.each do |s|
    with_three += 1 if s > 2
  end
  (with_three / word_count) * 100
end