Class: Twigg::Flesch

Inherits:
Object
  • Object
show all
Defined in:
lib/twigg/flesch.rb

Overview

Class which computes an approximation of the Flesch Reading Ease metric for a given piece of English-language text.

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Flesch

Returns a new instance of Flesch.



7
8
9
# File 'lib/twigg/flesch.rb', line 7

def initialize(string)
  @string = string
end

Instance Method Details

#reading_easeObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/twigg/flesch.rb', line 11

def reading_ease
  # from wikipedia:
  ease = 206.835 -
    1.015 * (total_words / total_sentences.to_f) -
    84.6  * (total_syllables / total_words.to_f)

  # beware NaN values (usually caused by empty commit messages),
  # incompatible with JSON
  ease.nan? ? 206.835 : ease
end