class CreepCheck

CreepCheck provides an API that applies the half-plus-seven formula to determine the social acceptability of a romantic relationship, based on the age difference between two people. This acceptability is codified as “creepiness”.

Given a date of April Fool's Day 2015, a dirty old man born in 1945 dating a young lady born in 2002 would definitely be considered a creep by the standards of the half-plus-seven formula, thus the “true” result.

Objects are instantiated by providing the birthdate of the subject of a creepcheck (e.g. yourself) and, optionally, a date you want the program to assume is the “current date”; if that date is not supplied, CreepCheck will use the actual current date for methods that require a “current” date.

The creep?, creep_limit, creep_limit_age, uncreepy_date, creep_limit_date, and uncreepy_range methods may all be invoked by sending a method to either the class or an instance of the class. Examples follow.

>> require 'creep_check'
=> true
>>
>> CreepCheck.creep?('1945-12-04', '2002-05-30')
=> true
>>
>> CreepCheck.creep_limit('1945-12-04', '2002-05-30')
=> 70.48459958932239
>>
>> CreepCheck.creep_limit_age('1945-12-04', '2002-05-30')
=> 126.96919917864476
>>
>> CreepCheck.uncreepy_date('1945-12-04', '2002-05-30')
=> #<Date: 2072-11-23 ((2478170j,43200s,0n),+0s,2299161j)>
>> puts _
2072-11-23
=> nil
>>
>> CreepCheck.creep_limit_date('1945-12-04', '2002-05-30')
=> #<Date: 2072-11-22 ((2478169j,43200s,0n),+0s,2299161j)>
>> puts _
2072-11-22
=> nil
>>
>> CreepCheck.uncreepy_range('1945-12-04')
=> [41.65982203969884, 124.63928815879535]

Both the creep? and uncreepy_range methods above optionally take an additional parameter that specifies a “current” date of the programmer's choosing.

>> subject = CreepCheck.new('1945-12-04')
=> #<CreepCheck:0x00000802a68da8 @bday="1945-12-04", @target_date=#<Date:
2015-03-31 ((2457113j,0s,0n),+0s,2299161j)>>
>>
>> subject.creep? '2002-05-30'
=> true
>>
>> subject.creep_limit '2002-05-30'
=> 70.48459958932239
>>
>> subject.creep_limit_age '2002-05-30'
=> 126.96919917864476
>>
>> subject.uncreepy_date '2002-05-30'
=> #<Date: 2072-11-23 ((2478170j,43200s,0n),+0s,2299161j)>
>> puts _
2072-11-23
=> nil
>>
>> subject.creep_limit_date '2002-05-30'
=> #<Date: 2072-11-22 ((2478169j,43200s,0n),+0s,2299161j)>
>> puts _
2072-11-22
=> nil
>>
>> subject.uncreepy_range
=> [41.65982203969884, 124.63928815879535]

When working with an instance of CreepCheck, no methods take a specified “current” date parameter except the new method, because the “current” date is a characteristic of the instance. Thus, the new method takes a specified “current” date as an optional parameter or, without the parameter, automatically sets the “current” date to the current date as of the instantiation of the object. Whether this behavior is correct is perhaps open to interpretation or debate, so it may change in some future version of CreepCheck.

Attributes

bday[R]
target_date[R]

Public Class Methods

array_to_date(date_array) click to toggle source
# File lib/creep_check.rb, line 211
def self.array_to_date(date_array)
  Date.new date_array[0].to_i, date_array[1].to_i, date_array[2].to_i
end
creep?(older_bday, newer_bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 132
def self.creep?(older_bday, newer_bday, target_date=Date.today)
  older = to_date older_bday
  newer = to_date newer_bday
  target = to_date target_date
  target - newer < creep_limit_days(older, newer)
end
creep_limit(older_bday, newer_bday) click to toggle source
# File lib/creep_check.rb, line 139
def self.creep_limit(older_bday, newer_bday)
  creep_limit_days(older_bday, newer_bday) / @@year
end
creep_limit_age(older_bday, newer_bday) click to toggle source
# File lib/creep_check.rb, line 143
def self.creep_limit_age(older_bday, newer_bday)
  creep_limit_age_days(older_bday, newer_bday) / @@year
end
creep_limit_age_days(older_bday, newer_bday) click to toggle source
# File lib/creep_check.rb, line 162
def self.creep_limit_age_days(older_bday, newer_bday)
  age_diff = to_date(newer_bday) - to_date(older_bday)
  @@days + age_diff * 2
end
creep_limit_date(older_bday, newer_bday) click to toggle source
# File lib/creep_check.rb, line 151
def self.creep_limit_date(older_bday, newer_bday)
  older = to_date older_bday
  newer = to_date newer_bday
  newer + creep_limit_days(older, newer)
end
creep_limit_days(older_bday, newer_bday) click to toggle source
# File lib/creep_check.rb, line 157
def self.creep_limit_days(older_bday, newer_bday)
  age_diff = to_date(newer_bday) - to_date(older_bday)
  @@days + age_diff
end
new(bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 99
def initialize(bday, target_date=Date.today)
  @bday = bday
  @target_date = target_date
end
to_date(date_value) click to toggle source
# File lib/creep_check.rb, line 198
def self.to_date(date_value)
  if date_value.class == Date
    date_value
  elsif date_value.class == Array
    array_to_date date_value
  elsif date_value.class == Hash
    Date.new self[:year], self[:month], self[:day]
  elsif date_value.class == String
    date_array = date_value.split('-')
    array_to_date date_array
  end
end
uncreepy_bounds_days(bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 175
def self.uncreepy_bounds_days(bday, target_date=Date.today)
  [
    uncreepy_lower_bound_days(bday, target_date),
    uncreepy_upper_bound_days(bday, target_date)
  ]
end
uncreepy_date(older_bday, newer_bday) click to toggle source
# File lib/creep_check.rb, line 147
def self.uncreepy_date(older_bday, newer_bday)
  creep_limit_date(older_bday, newer_bday) + 1
end
uncreepy_lower_bound(bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 182
def self.uncreepy_lower_bound(bday, target_date=Date.today)
  uncreepy_lower_bound_days(bday, target_date) / @@year
end
uncreepy_lower_bound_days(bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 190
def self.uncreepy_lower_bound_days(bday, target_date=Date.today)
  (to_date(target_date) - to_date(bday)) / 2.0 + @@seven
end
uncreepy_range(bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 167
def self.uncreepy_range(bday, target_date=Date.today)
  uncreepy_bounds_days(bday, target_date).collect {|days| days / @@year }
end
uncreepy_range_days(bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 171
def self.uncreepy_range_days(bday, target_date=Date.today)
  uncreepy_bounds_days(bday, target_date).join('-')
end
uncreepy_upper_bound(bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 186
def self.uncreepy_upper_bound(bday, target_date=Date.today)
  uncreepy_upper_bound_days(bday, target_date) / @@year
end
uncreepy_upper_bound_days(bday, target_date=Date.today) click to toggle source
# File lib/creep_check.rb, line 194
def self.uncreepy_upper_bound_days(bday, target_date=Date.today)
  (to_date(target_date) - to_date(bday) - @@seven) * 2
end
version() click to toggle source
# File lib/creep_check.rb, line 104
def self.version
  '3182.0.2'
end

Public Instance Methods

creep?(younger) click to toggle source
# File lib/creep_check.rb, line 108
def creep?(younger)
  CreepCheck.creep? @bday, younger, @target_date
end
creep_limit(younger) click to toggle source
# File lib/creep_check.rb, line 112
def creep_limit(younger)
  CreepCheck.creep_limit @bday, younger
end
creep_limit_age(younger) click to toggle source
# File lib/creep_check.rb, line 116
def creep_limit_age(younger)
  CreepCheck.creep_limit_age @bday, younger
end
creep_limit_date(younger) click to toggle source
# File lib/creep_check.rb, line 124
def creep_limit_date(younger)
  CreepCheck.creep_limit_date @bday, younger
end
uncreepy_date(younger) click to toggle source
# File lib/creep_check.rb, line 120
def uncreepy_date(younger)
  CreepCheck.uncreepy_date @bday, younger
end
uncreepy_range() click to toggle source
# File lib/creep_check.rb, line 128
def uncreepy_range
  CreepCheck.uncreepy_range @bday, @target_date
end