Class: FleschKincaid::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/flesch_kincaid/result.rb

Overview

Internal: A test result object, containing the score, grade, and notes.

Examples

@result = Result.new(80)
@result.score # => 80.0

@result = Result.new(80)
@result.grade # => "6th grade"

@result = Result.new(80)
@result.notes # => "Easy to read. Conversational English for consumers."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(score) ⇒ Result

Initialize a new Result

score - The Flesh Kincaid formula result score.



28
29
30
# File 'lib/flesch_kincaid/result.rb', line 28

def initialize(score)
  @score = score.to_f
end

Instance Attribute Details

#scoreObject (readonly)

The Flesh Kincaid formula result score.

Returns Float



21
22
23
# File 'lib/flesch_kincaid/result.rb', line 21

def score
  @score
end

Instance Method Details

#gradeObject

Approx. reading age for score.

Returns String



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/flesch_kincaid/result.rb', line 35

def grade
  case score
  when 90..100 then "5th grade"
  when 80..90  then "6th grade"
  when 70..80  then "7th grade"
  when 60..70  then "8th & 9th grade"
  when 50..60  then "10th to 12th grade"
  when 30..50  then "College"
  when 1..30   then "College Graduate"
  else
    "n/a"
  end
end

#notesObject

Additional notes to describe the score

Returns String



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/flesch_kincaid/result.rb', line 52

def notes
  case score
  when 90..100
    "Very easy to read. Easily understood by an average 11-year-old student."
  when 80..90
    "Easy to read. Conversational English for consumers."
  when 70..80
    "Fairly easy to read."
  when 60..70
    "Plain English. Easily understood by 13-15-year-old students."
  when 50..60
    "Fairly difficult to read."
  when 30..50
    "Difficult to read."
  when 1..30
    "Very difficult to read. Best understood by university graduates."
  else
    "No score available"
  end
end