Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Flesch-Kincaid formulas #5

Merged
merged 3 commits into from
Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ end

desc "Run tests"
task :default => :spec

task :console do
require 'pry'
require 'awesome_print'
require 'odyssey'
AwesomePrint.pry!
ARGV.clear
Pry.start
end
10 changes: 5 additions & 5 deletions lib/odyssey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ module Odyssey

#main method
def self.analyze(text, formula_name = DEFAULT_FORMULA, all_stats = false)
#catch nils
formula_name = DEFAULT_FORMULA if formula_name == nil
formula_name ||= DEFAULT_FORMULA

@engine = Odyssey::Engine.new(formula_name)
score = @engine.score(text)
Expand All @@ -23,10 +22,11 @@ def self.analyze(text, formula_name = DEFAULT_FORMULA, all_stats = false)
end

#run whatever method was given as if it were a shortcut to a formula
def self.method_missing(*args)
def self.method_missing(method_name, *args, &block)
#send to the main method
formula_class = args[0].to_s.split("_").map { |s| s.capitalize! }.join
analyze(args[1], formula_class, args[2] || false)
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

#define this here, so it doesn't get sent to method_missing()
Expand Down
1 change: 1 addition & 0 deletions odyssey.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.1.0"
spec.add_development_dependency "pry"
end
5 changes: 2 additions & 3 deletions spec/odyssey_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@
result['name'].should == "It's fake"
end

it 'should default to Formula for a formula that does not exist' do
result = Odyssey.no_existe one_simple_sentence, true
result['name'].should == "Generic"
it 'should raise an error for a formula that does not exist' do
expect { Odyssey.no_existe one_simple_sentence, true }.to raise_error(NoMethodError)
end
end
end