Class: CustomSort::SortFields
- Inherits:
-
Object
- Object
- CustomSort::SortFields
- Defined in:
- lib/custom_sort.rb
Class Method Summary collapse
- .time_decay(table_name, time_column = "created_at") ⇒ Object
- .time_decay_adjusted(table_name, lambda_key) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ SortFields
constructor
A new instance of SortFields.
Constructor Details
#initialize ⇒ SortFields
Returns a new instance of SortFields.
30 31 32 |
# File 'lib/custom_sort.rb', line 30 def initialize end |
Class Method Details
.time_decay(table_name, time_column = "created_at") ⇒ Object
33 34 35 |
# File 'lib/custom_sort.rb', line 33 def self.time_decay table_name, time_column = "created_at" "EXTRACT(EPOCH FROM (NOW()::timestamp - #{table_name}.#{time_column}::timestamp))/(24*60*60)" end |
.time_decay_adjusted(table_name, lambda_key) ⇒ Object
37 38 39 40 41 |
# File 'lib/custom_sort.rb', line 37 def self.time_decay_adjusted table_name, lambda_key lambda_val = CustomSort::LAMBDA_VALUES[lambda_key] time_decay_query = CustomSort::SortFields.time_decay(table_name) lambda_val.nil? ? "1" : "exp(#{time_decay_query}*#{lambda_val})" end |