Module: Snails::RelativeTime
- Defined in:
- lib/snails/util.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.minutes_in_words(min) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/snails/util.rb', line 7 def self.minutes_in_words(min) case min.to_i when 0..1 then 'menos de un min' when 2..4 then 'menos de 5 min' when 5..14 then 'menos de 15 min' when 15..29 then "media hora" when 30..59 then "#{min} minutos" when 60..119 then '1 hora' when 120..239 then '2 horas' when 240..479 then '4 horas' when 480..719 then '8 horas' when 720..1439 then '12 horas' when 1440..11519 then "#{(min/1440).floor} días" when 11520..43199 then "#{(min/11520).floor} semanas" when 43200..525599 then "#{(min/43200).floor} meses" else "#{(min/525600).floor} años" end end |
Instance Method Details
#in_words ⇒ Object
26 27 28 29 30 |
# File 'lib/snails/util.rb', line 26 def in_words minutes = (((Time.now - self).abs)/60).round return nil if minutes < 0 RelativeTime.minutes_in_words(minutes) end |
#relative ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/snails/util.rb', line 32 def relative if str = in_words if Time.now < self # "#{str} más" "en #{str}" else "hace #{str}" end end end |