Class: UncleKryon::TimespanData
- Inherits:
-
Object
- Object
- UncleKryon::TimespanData
- Defined in:
- lib/unclekryon/data/timespan_data.rb
Instance Attribute Summary collapse
-
#hours ⇒ Object
Returns the value of attribute hours.
-
#mins ⇒ Object
Returns the value of attribute mins.
-
#secs ⇒ Object
Returns the value of attribute secs.
Instance Method Summary collapse
-
#initialize(time = nil) ⇒ TimespanData
constructor
A new instance of TimespanData.
- #to_s ⇒ Object
Constructor Details
#initialize(time = nil) ⇒ TimespanData
Returns a new instance of TimespanData.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/unclekryon/data/timespan_data.rb', line 22 def initialize(time=nil) @hours = 0 @mins = 0 @secs = 0 if !time.nil? && !(time = time.strip).empty? time = time.gsub(/\A[^\(]+\(/,'') # "One hour 6 minutes - (66 minutes)" time = time.gsub(/[^[[:digit:]]\:\.]+/,'') a = time.split(/[\:\.]/) if a.length == 1 @mins = a[0].to_i elsif a.length == 2 @mins = a[0].to_i @secs = a[1].to_i elsif a.length >= 3 @hours = a[0].to_i @mins = a[1].to_i @secs = a[2].to_i end if @secs >= 60 @mins += (@secs / 60) @secs = @secs % 60 end if @mins >= 60 @hours += (@mins / 60) @mins = @mins % 60 end end end |
Instance Attribute Details
#hours ⇒ Object
Returns the value of attribute hours.
18 19 20 |
# File 'lib/unclekryon/data/timespan_data.rb', line 18 def hours @hours end |
#mins ⇒ Object
Returns the value of attribute mins.
19 20 21 |
# File 'lib/unclekryon/data/timespan_data.rb', line 19 def mins @mins end |
#secs ⇒ Object
Returns the value of attribute secs.
20 21 22 |
# File 'lib/unclekryon/data/timespan_data.rb', line 20 def secs @secs end |
Instance Method Details
#to_s ⇒ Object
54 55 56 |
# File 'lib/unclekryon/data/timespan_data.rb', line 54 def to_s return "#{@hours}:#{@mins}:#{@secs}" end |