Class: Knj::Db::Dbtime

Inherits:
Object show all
Defined in:
lib/knj/knjdb/dbtime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Dbtime

Returns a new instance of Dbtime.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/knj/knjdb/dbtime.rb', line 4

def initialize(args)
  args = {:time => args} if args.is_a?(String)
  
  raise "Invalid arguments given." if !args.is_a?(Hash)
  raise "No time given." if !args[:time]
  raise "Invalid time given." if !args[:time].is_a?(String)
  
  match = args[:time].match(/^(\d+):(\d+):(\d+)$/)
  raise "Could not understand time format." if !match
  
  @hours = match[1].to_i
  @mins = match[2].to_i
  @secs = match[3].to_i
  
  @total_secs = @hours * 3600
  @total_secs += @mins * 60
  @total_secs += @secs
end

Instance Attribute Details

#hoursObject (readonly)

Returns the value of attribute hours.



2
3
4
# File 'lib/knj/knjdb/dbtime.rb', line 2

def hours
  @hours
end

#minsObject (readonly)

Returns the value of attribute mins.



2
3
4
# File 'lib/knj/knjdb/dbtime.rb', line 2

def mins
  @mins
end

#secsObject (readonly)

Returns the value of attribute secs.



2
3
4
# File 'lib/knj/knjdb/dbtime.rb', line 2

def secs
  @secs
end

#total_secsObject (readonly)

Returns the value of attribute total_secs.



2
3
4
# File 'lib/knj/knjdb/dbtime.rb', line 2

def total_secs
  @total_secs
end

Instance Method Details

#hours_totalObject



23
24
25
# File 'lib/knj/knjdb/dbtime.rb', line 23

def hours_total
  return (@total_secs.to_f / 3600)
end

#mins_totalObject



27
28
29
# File 'lib/knj/knjdb/dbtime.rb', line 27

def mins_total
  return (@total_secs.to_f / 60)
end