Class: Smog

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

Instance Method Summary collapse

Methods inherited from Odyssey::Formula

#score_by_sentence

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

#nameObject



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