Sha256: 42edc93d694ea02eb3f42703294b53632b359da073c839b51fb8af1281c1fb55
Contents?: true
Size: 641 Bytes
Versions: 4
Compression:
Stored size: 641 Bytes
Contents
require "my_age/helper" module MyAge module Calculator unless respond_to?(:dob) def self.included(base) def base.my_dob(col) define_method(:dob) { send col } end end end def age(date=Date.today) return 0 if dob.blank? || date.blank? || date <= dob (date_to_int(date) - date_to_int(dob))/10_000 end def method_missing(name, *args) if name.to_s =~ /_as_of_/ date_method = name.to_s.split("_as_of_")[-1] age today.send(date_method.to_sym, *args) else super end end private def date_to_int(date) date.strftime("%Y%m%d").to_i end def today Date.today end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
my_age-0.1.5 | lib/my_age/calculator.rb |
my_age-0.1.4 | lib/my_age/calculator.rb |
my_age-0.1.3 | lib/my_age/calculator.rb |
my_age-0.1.2 | lib/my_age/calculator.rb |