Class: Smog

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

Instance Method Summary collapse

Instance Method Details

#calc_score(sentence_count, with_three) ⇒ Object



16
17
18
# File 'lib/formulas/smog.rb', line 16

def calc_score(sentence_count, with_three)
  (1.043 * Math.sqrt(with_three * (30.0 / sentence_count)) + 3.1291).round(1)
end

#nameObject



20
21
22
# File 'lib/formulas/smog.rb', line 20

def name
  'SMOG Index'
end

#score(text, stats) ⇒ Object



3
4
5
6
# File 'lib/formulas/smog.rb', line 3

def score(text, stats)
  with_three = three_syllables(text['syllables'])
  calc_score(stats['sentence_count'], with_three)
end

#three_syllables(syllables) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/formulas/smog.rb', line 8

def three_syllables(syllables)
  with_three = 0
  syllables.each do |s|
    with_three += 1 if s > 2
  end
  with_three
end