Class: Ranker::Strategies::Strategy
- Inherits:
-
Object
- Object
- Ranker::Strategies::Strategy
- Defined in:
- lib/ranker/strategies/strategy.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#rankables ⇒ Object
readonly
Returns the value of attribute rankables.
Instance Method Summary collapse
-
#errors ⇒ Object
Properties:.
-
#initialize(rankables, *args) ⇒ Strategy
constructor
A new instance of Strategy.
- #rank ⇒ Object
- #rankings ⇒ Object
- #scores ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(rankables, *args) ⇒ Strategy
Returns a new instance of Strategy.
7 8 9 10 11 12 13 14 15 |
# File 'lib/ranker/strategies/strategy.rb', line 7 def initialize(rankables, *args) @rankables = rankables = args.pop if && .kind_of?(Hash) @options = .merge() else @options = end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/ranker/strategies/strategy.rb', line 5 def @options end |
#rankables ⇒ Object (readonly)
Returns the value of attribute rankables.
5 6 7 |
# File 'lib/ranker/strategies/strategy.rb', line 5 def rankables @rankables end |
Instance Method Details
#errors ⇒ Object
Properties:
20 21 22 |
# File 'lib/ranker/strategies/strategy.rb', line 20 def errors @errors ||= {} end |
#rank ⇒ Object
41 42 43 44 45 46 |
# File 'lib/ranker/strategies/strategy.rb', line 41 def rank raise Error.new(errors) unless valid? execute rankings end |
#rankings ⇒ Object
24 25 26 |
# File 'lib/ranker/strategies/strategy.rb', line 24 def rankings @rankings ||= Ranker::Rankings.new(self) end |
#scores ⇒ Object
28 29 30 |
# File 'lib/ranker/strategies/strategy.rb', line 28 def scores rankables_grouped_by_score.keys end |
#valid? ⇒ Boolean
32 33 34 35 |
# File 'lib/ranker/strategies/strategy.rb', line 32 def valid? validate errors.empty? end |