Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/theampm.rb

Instance Method Summary collapse

Instance Method Details

#amObject

A convenience for writing: 3.am or 1130.am



6
7
8
# File 'lib/theampm.rb', line 6

def am
  Chronic.parse("#{self.to_s} am")
end

#pmObject



10
11
12
# File 'lib/theampm.rb', line 10

def pm
  Chronic.parse("#{self.to_s} pm")
end

#to_timeObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/theampm.rb', line 14

def to_time
  hour = self
  if hour < 12 || (hour >= 100 && hour < 1200)
    Chronic.parse("#{self.to_s} am")
  elsif hour >= 24
    Chronic.parse("#{self.to_s}")
  else
    Chronic.parse("#{self.to_s} pm")
  end
end