Sha256: ca77103a12a39b61e31e752811b723f5bb8b4fc491482821ae958d9131c280ef

Contents?: true

Size: 737 Bytes

Versions: 26

Compression:

Stored size: 737 Bytes

Contents

class Knj::Db::Dbtime
  attr_reader :hours, :mins, :secs, :total_secs
  
  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
  
  def hours_total
    return (@total_secs.to_f / 3600)
  end
  
  def mins_total
    return (@total_secs.to_f / 60)
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
knjrbfw-0.0.30 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.29 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.28 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.27 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.26 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.25 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.24 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.23 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.22 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.21 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.20 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.19 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.18 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.17 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.16 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.15 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.14 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.13 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.12 lib/knj/knjdb/dbtime.rb
knjrbfw-0.0.11 lib/knj/knjdb/dbtime.rb