Module: Odyssey
- Defined in:
- lib/odyssey.rb,
lib/odyssey/engine.rb,
lib/odyssey/version.rb
Defined Under Namespace
Classes: Engine
Constant Summary collapse
- DEFAULT_FORMULA =
'FleschKincaidRe'
- VERSION =
"0.2.0"
Class Method Summary collapse
-
.analyze(text, formula_name = DEFAULT_FORMULA, all_stats = false) ⇒ Object
main method.
- .analyze_multi(text, formula_names, all_stats = false) ⇒ Object
-
.method_missing(method_name, *args, &block) ⇒ Object
run whatever method was given as if it were a shortcut to a formula.
-
.to_ary ⇒ Object
define this here, so it doesn’t get sent to method_missing().
Class Method Details
.analyze(text, formula_name = DEFAULT_FORMULA, all_stats = false) ⇒ Object
main method
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/odyssey.rb', line 8 def self.analyze(text, formula_name = DEFAULT_FORMULA, all_stats = false) formula_name ||= DEFAULT_FORMULA @engine = Odyssey::Engine.new(formula_name) score = @engine.score(text) #return all stats? if all_stats output = @engine.get_stats else output = score end output end |
.analyze_multi(text, formula_names, all_stats = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/odyssey.rb', line 24 def self.analyze_multi(text, formula_names, all_stats = false) raise ArgumentError, "You must supply at least one formula" if formula_names.empty? scores = {} @engine = Odyssey::Engine.new(formula_names[0]) scores[formula_names[0]] = @engine.score(text) formula_names.drop(1).each do |formula_name| @engine.update_formula(formula_name) scores[formula_name] = @engine.score("", false) end if all_stats all_stats = @engine.get_stats(false) all_stats['scores'] = scores output = all_stats else output = scores end output end |
.method_missing(method_name, *args, &block) ⇒ Object
run whatever method was given as if it were a shortcut to a formula
48 49 50 51 52 53 |
# File 'lib/odyssey.rb', line 48 def self.method_missing(method_name, *args, &block) #send to the main method formula_class = method_name.to_s.split("_").map(&:capitalize).join super unless Object.const_defined? formula_class analyze(args[0], formula_class, args[1] || false) end |
.to_ary ⇒ Object
define this here, so it doesn’t get sent to method_missing()
56 57 58 |
# File 'lib/odyssey.rb', line 56 def self.to_ary [] end |