Class: ColemanLiau

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

Instance Method Summary collapse

Instance Method Details

#calc_score(letter_count, word_count, sentence_count) ⇒ Object



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

def calc_score(letter_count, word_count, sentence_count)
  ((5.89 * (letter_count.to_f / word_count.to_f)) - (0.3 * (sentence_count.to_f / word_count.to_f)) - 15.8).round(1)
end

#nameObject



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

def name
  'Coleman-Liau Index'
end

#score(text, stats) ⇒ Object



3
4
5
# File 'lib/odyssey/formulas/coleman_liau.rb', line 3

def score(text, stats)
  calc_score(stats['letter_count'], stats['word_count'], stats['sentence_count'])
end

#score_by_sentence(text, stats_split) ⇒ Object



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

def score_by_sentence(text, stats_split)
  res = []
  for i in 0..text['sentences'].length-1
    res.push(calc_score(stats_split['letter_count'][i],
                        stats_split['word_count'][i],
                        1))
  end
end