Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/fuzzy_time.rb
Instance Method Summary collapse
-
#fuzzy ⇒ Object
Display the current time in a human-readable format.
Instance Method Details
#fuzzy ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fuzzy_time.rb', line 12 def fuzzy # convert from 24 to 12-hour clock hour = self.hour % 12 min = self.min hour = hour + 1 if min >= 33 hour = case hour when 1; "one" when 2; "two" when 3; "three" when 4; "four" when 5; "five" when 6; "six" when 7; "seven" when 8; "eight" when 9; "nine" when 10; "ten" when 11; "eleven" when 12, 0; "twelve" end return "#{hour} o'clock" if min == 0 prefix = case min when 1..2; "shortly after" when 3..7; "five past" when 8..12; "ten past" when 13..17; "quarter past" when 18..22; "twenty past" when 23..27; "twentyfive past" when 28..32; "half past" when 33..37; "twentyfive to" when 38..42; "twenty to" when 43..47; "quarter to" when 48..52; "ten to" when 53..57; "five to" when 58..59; "nearly" end "#{prefix} #{hour}" end |