class Tempo::Views::ViewRecords::Duration

Specifically for managing a time duration, nested in other view records. This can be used with a start and end time, or used to manage a sum of times.

Total duration is stored in seconds.

Duration records can be further queried for hours and minutes in order to construct a human redable duration. This can be used to construct time as #{hours}:#{minutes} Hours returns the total whole hours, minutes returns the remaining whole minutes after the hours have been removed from the total.

Attributes

total[RW]
type[RW]

Public Class Methods

new(seconds=0) click to toggle source
# File lib/tempo/views/view_records/base.rb, line 88
def initialize seconds=0
  @type = "duration"
  @total = seconds
end

Public Instance Methods

add(seconds) click to toggle source
# File lib/tempo/views/view_records/base.rb, line 100
def add(seconds)
  @total += seconds
end
format(&block) click to toggle source
# File lib/tempo/views/view_records/base.rb, line 93
def format(&block)
  block ||= lambda do |d|
    "#{ d.hours.to_s }:#{ d.minutes.to_s.rjust(2, '0') }"
  end
  block.call self
end
hours() click to toggle source
# File lib/tempo/views/view_records/base.rb, line 108
def hours
  hours = ( @total / 3600 ).to_i
end
minutes() click to toggle source
# File lib/tempo/views/view_records/base.rb, line 112
def minutes
  minutes = ( @total / 60 - hours * 60 ).to_i
end
subtract(seconds) click to toggle source
# File lib/tempo/views/view_records/base.rb, line 104
def subtract(seconds)
  @total -= seconds
end