Class: Workpattern::Clock

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

Overview

Represents time on a clock in hours and minutes.

Examples:

myClock=Clock.new(3,32)
myClock.minutes #=> 212
myClock.hour #=> 3
myClock.min  #=> 32
myClock.time #=> Time.new(1963,6,10,3,32)
myClock.to_s #=> 3:32 212 

aClock=Clock.new(27,80)
aClock.minutes #=> 1700
aClock.hour #=> 4
aClock.min #=> 20
aClock.time #=> Time.new(1963,6,10,4,20)
aClock.to_s #=> 4:20 1700

Since:

  • 0.2.0

Instance Method Summary collapse

Constructor Details

#initialize(hour = 0, min = 0) ⇒ Clock

Initialises an instance of Clock using the hours and minutes supplied or 0 if they are absent. Although there are 24 hours in a day (0-23) and 60 minutes in an hour (0-59), Clock calculates the full hours and remaining minutes of whatever is supplied.

Since:

  • 0.2.0


31
32
33
34
# File 'lib/workpattern/clock.rb', line 31

def initialize(hour=0,min=0)
  @hour = total_minutes(hour,min).div(60)
  @min = total_minutes(hour,min) % 60
end

Instance Method Details

#hourInteger

Returns the hour of the clock (0-23)

Since:

  • 0.2.0


48
49
50
# File 'lib/workpattern/clock.rb', line 48

def hour
  return @hour % 24
end

#minInteger

Returns the minute of the clock (0-59)

Since:

  • 0.2.0


56
57
58
# File 'lib/workpattern/clock.rb', line 56

def min
  return @min % 60
end

#minutesInteger

Returns the total number of minutes

Since:

  • 0.2.0


40
41
42
# File 'lib/workpattern/clock.rb', line 40

def minutes
  return total_minutes(@hour,@min)
end

#timeDateTime

Returns a Time object with the correct hour and min values. The date is 10th June 1963.

Since:

  • 0.2.0


65
66
67
# File 'lib/workpattern/clock.rb', line 65

def time
  return DateTime.new(1963,6,10,hour,min)
end

#to_sString

Returns representation of Clock value as 'hh:mn minutes'

Since:

  • 0.2.0


71
72
73
# File 'lib/workpattern/clock.rb', line 71

def to_s      
  hour.to_s.concat(':').concat(min.to_s).concat(' ').concat(minutes.to_s)
end