Class: Ranker::Ranking

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rankings, index, rank, score, rankables) ⇒ Ranking

Returns a new instance of Ranking.



7
8
9
10
11
12
13
# File 'lib/ranker/ranking.rb', line 7

def initialize(rankings, index, rank, score, rankables)
  @rankings = rankings
  @index = index
  @rank = rank
  @score = score
  @rankables = rankables
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#rankObject (readonly)

Returns the value of attribute rank.



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

def rank
  @rank
end

#rankablesObject (readonly)

Returns the value of attribute rankables.



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

def rankables
  @rankables
end

#rankingsObject (readonly)

Returns the value of attribute rankings.



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

def rankings
  @rankings
end

#scoreObject (readonly)

Returns the value of attribute score.



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

def score
  @score
end

Instance Method Details

#num_rankablesObject

Properties:



17
18
19
# File 'lib/ranker/ranking.rb', line 17

def num_rankables
  rankables.count
end

#percentileObject



21
22
23
# File 'lib/ranker/ranking.rb', line 21

def percentile
  @percentile ||= (num_scores_at_or_below.to_f / rankings.num_scores) * 100
end

#z_scoreObject



25
26
27
28
29
30
31
# File 'lib/ranker/ranking.rb', line 25

def z_score
  @z_score ||= if rankings.standard_deviation == 0
    0
  else
    (score - rankings.mean) / rankings.standard_deviation
  end
end