Module: Acts::Elo::ClassMethods
- Defined in:
- lib/acts_as_elo/acts/elo.rb
Instance Method Summary collapse
-
#acts_as_elo(opts = {}) ⇒ Object
‘acts_as_elo` hooks into your object to provide you with the ability to set and get `elo_rank` attribute Available options are: * default_rank - change the starting rank * one_way - limits update of the rank to only self * proficiency_map - hash that has two keys * rank_limits - array of two elements, ranks that limit categories of player proficiency.
Instance Method Details
#acts_as_elo(opts = {}) ⇒ Object
‘acts_as_elo` hooks into your object to provide you with the ability to set and get `elo_rank` attribute Available options are:
-
default_rank - change the starting rank
-
one_way - limits update of the rank to only self
-
proficiency_map - hash that has two keys
* rank_limits - array of two elements, ranks that limit categories of player proficiency. Between novice and intermediate; intermediate and pro. Defaults: 1299, 2399 * coefficients - proficiency coefficient for each category. Defaults: 30 for novice, 15 for intermediate, 10 for a pro
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/acts_as_elo/acts/elo.rb', line 19 def acts_as_elo(opts = {}) default_rank = opts[:default_rank] || 1200 proficiency_map = opts[:proficiency_map] || {:coefficients => [30, 15, 10], :rank_limits => [1299, 2399] } unless opts.empty? class << self attr_accessor :acts_as_elo_options end @acts_as_elo_options = opts end class_eval do if Object::const_defined?("ActiveRecord") && self.ancestors.include?(ActiveRecord::Base) define_method(:elo_rank) do self[:elo_rank] ||= default_rank end else attr_writer :elo_rank define_method(:elo_rank) do @elo_rank ||= default_rank end end define_method(:elo_proficiency_map) do proficiency_map end end include Acts::Elo::InstanceMethods unless self.included_modules.include?(Acts::Elo::InstanceMethods) end |