class SlideRule::DistanceCalculators::DayOfMonth
Constants
- MAX_DAYS
Public Instance Methods
calculate(first, second, options={})
click to toggle source
Calculates distance using 15 as the max point.
Does not take into account the number of days in the actual month being considered.
# File lib/slide_rule/distance_calculators/day_of_month.rb, line 10 def calculate(first, second, options={}) return nil if first.nil? || second.nil? first = cleanse_date(first) second = cleanse_date(second) difference_in_days(first, second).to_f / MAX_DAYS end
difference_in_days(first, second)
click to toggle source
# File lib/slide_rule/distance_calculators/day_of_month.rb, line 18 def difference_in_days(first, second) distance = (first.mday - second.mday).abs return distance if distance <= MAX_DAYS MAX_DAYS - (distance - MAX_DAYS) end
Private Instance Methods
cleanse_date(date)
click to toggle source
# File lib/slide_rule/distance_calculators/day_of_month.rb, line 26 def cleanse_date(date) date = Time.at(date).utc.to_date if date.is_a?(::Integer) date = Date.parse(date) unless date.is_a?(::Date) || date.is_a?(::Time) date = date.to_date if date.is_a?(::Time) date end