Class: Ranker::Strategies::Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/ranker/strategies/strategy.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  options = args.pop
  if options && options.kind_of?(Hash)
    @options = default_options.merge(options)
  else
    @options = default_options
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/ranker/strategies/strategy.rb', line 5

def options
  @options
end

#rankablesObject (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

#errorsObject

Properties:



20
21
22
# File 'lib/ranker/strategies/strategy.rb', line 20

def errors
  @errors ||= {}
end

#rankObject

Raises:



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

#rankingsObject



24
25
26
# File 'lib/ranker/strategies/strategy.rb', line 24

def rankings
  @rankings ||= Ranker::Rankings.new(self)
end

#scoresObject



28
29
30
# File 'lib/ranker/strategies/strategy.rb', line 28

def scores
  rankables_grouped_by_score.keys
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/ranker/strategies/strategy.rb', line 32

def valid?
  validate
  errors.empty?
end