Class: Rankles::Reddit

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Reddit

Setup data for ranking calculation. Required options:

  • :date

  • :upvotes

  • :downvotes



10
11
12
13
14
# File 'lib/rankles.rb', line 10

def initialize(options = {})
  self.date      = options[:date]
  self.upvotes   = options[:upvotes]
  self.downvotes = options[:downvotes]
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/rankles.rb', line 4

def date
  @date
end

#downvotesObject

Returns the value of attribute downvotes.



4
5
6
# File 'lib/rankles.rb', line 4

def downvotes
  @downvotes
end

#upvotesObject

Returns the value of attribute upvotes.



4
5
6
# File 'lib/rankles.rb', line 4

def upvotes
  @upvotes
end

Instance Method Details

#to_fObject

Gives the result of the reddit algorithm. Higher is better.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rankles.rb', line 19

def to_f
  ts = date - Time.utc(2005, 12, 8, 7, 46, 43)
  x = upvotes - downvotes

  y = case
      when x > 0  then 1
      when x == 0 then 0
      when x < 0  then -1
      end

  z = if x.abs >= 1
        x.abs
      else
        1
      end

  Math.log10(z) + (y * ts) / 12.5.hours
end