Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/matching/similarity.rb
Overview
Adds fuzzy methods to standard classes for comparing two instances on a rules-based scale between 0.0 and 1.0.
Instance Method Summary collapse
-
#similarity_to(other_date, opts = {}) ⇒ Object
Calculates a score between 0.0 and 1.0 for all dates within :days_scale of each other.
Instance Method Details
#similarity_to(other_date, opts = {}) ⇒ Object
Calculates a score between 0.0 and 1.0 for all dates within :days_scale of each other.
11 12 13 14 15 16 17 18 |
# File 'lib/matching/similarity.rb', line 11 def similarity_to(other_date, opts={}) days_scale = opts[:days_scale] || 30 raise ArgumentError, 'days_scale must be numeric' unless days_scale.class == Fixnum days_scale = days_scale.to_f delta = (self - other_date).to_f.abs (delta < days_scale ? (days_scale - delta) / days_scale : 0.0) end |