Class: Smog
- Inherits:
-
Odyssey::Formula
- Object
- Odyssey::Formula
- Smog
- Defined in:
- lib/odyssey/formulas/smog.rb
Instance Method Summary collapse
- #calc_score(sentence_count, with_three) ⇒ Object
- #name ⇒ Object
- #score(text, stats) ⇒ Object
- #score_per_sentence(text, stats_split) ⇒ Object
- #three_syllables(syllables) ⇒ Object
Methods inherited from Odyssey::Formula
Instance Method Details
#calc_score(sentence_count, with_three) ⇒ Object
25 26 27 |
# File 'lib/odyssey/formulas/smog.rb', line 25 def calc_score(sentence_count, with_three) (1.043 * Math.sqrt(with_three * (30.0 / sentence_count)) + 3.1291).round(1) end |
#name ⇒ Object
29 30 31 |
# File 'lib/odyssey/formulas/smog.rb', line 29 def name 'SMOG Index' end |
#score(text, stats) ⇒ Object
3 4 5 6 |
# File 'lib/odyssey/formulas/smog.rb', line 3 def score(text, stats) with_three = three_syllables(text['syllables']) calc_score(stats['sentence_count'], with_three) end |
#score_per_sentence(text, stats_split) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/odyssey/formulas/smog.rb', line 8 def score_per_sentence(text, stats_split) res = [] for i in 0..text['sentences'].length-1 with_three = three_syllables(text['syllables_per_sentence'][i]) res.push(calc_score(1, with_three)) end res end |
#three_syllables(syllables) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/odyssey/formulas/smog.rb', line 17 def three_syllables(syllables) with_three = 0 syllables.each do |s| with_three += 1 if s > 2 end with_three end |