Skip to content

Instantly share code, notes, and snippets.

@chrisjones
Created November 1, 2010 01:09
Show Gist options
  • Save chrisjones/657413 to your computer and use it in GitHub Desktop.
Save chrisjones/657413 to your computer and use it in GitHub Desktop.
qbrating.rb
require 'qbrating'
#Order: Completions, Attempts, Yards Completed, TDs, Interceptions
qb = QBRating.new(26,45,212,4,1)
puts "\nThe QB Rating is #{qb}."
class QBRating
attr_accessor :rating
def initialize(comp,att,yards,td,int)
@rating = ((rule1(att,comp) + rule2(yards,att) + rule3(td,att) + rule4(int,att)) / 6) * 100
end
def to_s
@rating = "%3.1f" % @rating
end
private
def rule1(att,comp)
return check_boundary(((comp.to_f / att.to_f * 100) - 30.0) * 0.05)
end
def rule2(yards,att)
return check_boundary(((yards.to_f / att.to_f) - 3.0) * 0.25)
end
def rule3(td,att)
return check_boundary(td.to_f / att.to_f * 100 * 0.2)
end
def rule4(int,att)
return check_boundary(2.375 - (int.to_f / att.to_f * 100 * 0.25))
end
def check_boundary(part)
if part < 0
part = 0
elsif part > 2.375
part = 2.375
end
return part
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment