Class: Baza::Dbtime
- Inherits:
-
Object
- Object
- Baza::Dbtime
- Defined in:
- lib/baza/dbtime.rb
Overview
This class helps handeling time-columns in databases.
Instance Attribute Summary collapse
-
#hours ⇒ Object
readonly
These variables return information about the object.
-
#mins ⇒ Object
readonly
These variables return information about the object.
-
#secs ⇒ Object
readonly
These variables return information about the object.
-
#total_secs ⇒ Object
readonly
These variables return information about the object.
Instance Method Summary collapse
-
#hours_total ⇒ Object
Returns the total amount of hours.
-
#initialize(args) ⇒ Dbtime
constructor
Initializes the object from arguments useually given by Baza::Datarow.
-
#mins_total ⇒ Object
Return the total amount of minutes.
Constructor Details
#initialize(args) ⇒ Dbtime
Initializes the object from arguments useually given by Baza::Datarow.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/baza/dbtime.rb', line 7 def initialize(args) args = {time: args} if args.is_a?(String) raise "Invalid arguments given: #{args}" unless args.is_a?(Hash) raise "No time given." unless args[:time] raise "Invalid time given: #{args[:time].class.name}" unless args[:time].is_a?(String) match = args[:time].match(/^(\d+):(\d+):(\d+)$/) raise "Could not understand time format." unless 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)
These variables return information about the object.
4 5 6 |
# File 'lib/baza/dbtime.rb', line 4 def hours @hours end |
#mins ⇒ Object (readonly)
These variables return information about the object.
4 5 6 |
# File 'lib/baza/dbtime.rb', line 4 def mins @mins end |
#secs ⇒ Object (readonly)
These variables return information about the object.
4 5 6 |
# File 'lib/baza/dbtime.rb', line 4 def secs @secs end |
#total_secs ⇒ Object (readonly)
These variables return information about the object.
4 5 6 |
# File 'lib/baza/dbtime.rb', line 4 def total_secs @total_secs end |
Instance Method Details
#hours_total ⇒ Object
Returns the total amount of hours.
27 28 29 |
# File 'lib/baza/dbtime.rb', line 27 def hours_total (@total_secs.to_f / 3600) end |
#mins_total ⇒ Object
Return the total amount of minutes.
32 33 34 |
# File 'lib/baza/dbtime.rb', line 32 def mins_total (@total_secs.to_f / 60) end |