Class: GunningFog

Inherits:
Odyssey::Formula show all
Defined in:
lib/odyssey/formulas/gunning_fog.rb

Instance Method Summary collapse

Methods inherited from Odyssey::Formula

#score_by_sentence

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

#nameObject



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