Sha256: 3b51deb3d37c659f483b67b9ba1791c7973229a71cb566e53e3221792b296de0
Contents?: true
Size: 1.09 KB
Versions: 48
Compression:
Stored size: 1.09 KB
Contents
# encoding: utf-8 class Antiquity def initialize(periods) @periods = periods.sort { |a,b| a.start_date <=> b.start_date } end def days @periods.inject(0) { |total, period| total + period.days } end def months @periods.inject(0) { |total, period| total + period.months } end def years months.divmod(12).first end def to_s date = (@periods.last && @periods.last.end_date) || Date.today result = "" return result if @periods.empty? if date >= @periods.first.start_date result += years > 1 ? "#{years} años" : "#{years} año" unless years == 0 result += ", " if years >= 1 && !(months.modulo(12).eql?(0)) result += months.modulo(12) > 1 ? "#{months.modulo(12)} meses" : "#{months.modulo(12)} mes" unless months.modulo(12) == 0 result += "#{(date - @periods.last.start_date).to_i} dias" if months.modulo(12) == 0 && years == 0 && date > @periods.last.start_date result += "Hoy!" if months.modulo(12) == 0 && date == @periods.last.start_date end result += "En unos días..." if date < @periods.first.start_date result end end
Version data entries
48 entries across 48 versions & 1 rubygems