Class: Knj::Db::Dbtime
Instance Attribute Summary collapse
-
#hours ⇒ Object
readonly
Returns the value of attribute hours.
-
#mins ⇒ Object
readonly
Returns the value of attribute mins.
-
#secs ⇒ Object
readonly
Returns the value of attribute secs.
-
#total_secs ⇒ Object
readonly
Returns the value of attribute total_secs.
Instance Method Summary collapse
- #hours_total ⇒ Object
-
#initialize(args) ⇒ Dbtime
constructor
A new instance of Dbtime.
- #mins_total ⇒ Object
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
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
2 3 4 |
# File 'lib/knj/knjdb/dbtime.rb', line 2 def hours @hours end |
#mins ⇒ Object (readonly)
Returns the value of attribute mins.
2 3 4 |
# File 'lib/knj/knjdb/dbtime.rb', line 2 def mins @mins end |
#secs ⇒ Object (readonly)
Returns the value of attribute secs.
2 3 4 |
# File 'lib/knj/knjdb/dbtime.rb', line 2 def secs @secs end |
#total_secs ⇒ Object (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 |