Class: Rankles::Reddit
- Inherits:
-
Object
- Object
- Rankles::Reddit
- Defined in:
- lib/rankles.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#downvotes ⇒ Object
Returns the value of attribute downvotes.
-
#upvotes ⇒ Object
Returns the value of attribute upvotes.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Reddit
constructor
Setup data for ranking calculation.
-
#to_f ⇒ Object
.
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( = {}) self.date = [:date] self.upvotes = [:upvotes] self.downvotes = [:downvotes] end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
4 5 6 |
# File 'lib/rankles.rb', line 4 def date @date end |
#downvotes ⇒ Object
Returns the value of attribute downvotes.
4 5 6 |
# File 'lib/rankles.rb', line 4 def downvotes @downvotes end |
#upvotes ⇒ Object
Returns the value of attribute upvotes.
4 5 6 |
# File 'lib/rankles.rb', line 4 def upvotes @upvotes end |
Instance Method Details
#to_f ⇒ Object
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 |