Class: GunningFog
- Inherits:
-
Odyssey::Formula
- Object
- Odyssey::Formula
- GunningFog
- Defined in:
- lib/odyssey/formulas/gunning_fog.rb
Instance Method Summary collapse
- #calc_score(avg_words, percent_with_three) ⇒ Object
- #name ⇒ Object
- #score(text, stats) ⇒ Object
- #score_per_sentence(text, stats_split) ⇒ Object
-
#three_syllables(word_count, syllables) ⇒ Object
percentage of words with three syllables.
Methods inherited from Odyssey::Formula
Instance Method Details
#calc_score(avg_words, percent_with_three) ⇒ Object
27 28 29 |
# 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 ⇒ Object
31 32 33 |
# File 'lib/odyssey/formulas/gunning_fog.rb', line 31 def name 'Gunning-Fog Score' end |
#score(text, stats) ⇒ Object
3 4 5 6 |
# 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) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# 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) ⇒ Object
percentage of words with three syllables
19 20 21 22 23 24 25 |
# 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 |