Class: TimeWin::Window
- Inherits:
-
Object
- Object
- TimeWin::Window
- Defined in:
- lib/time_win/window.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#to ⇒ Object
readonly
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(from, to) ⇒ Window
constructor
A new instance of Window.
- #nb_days ⇒ Object
- #nb_hours ⇒ Object
- #nb_minutes ⇒ Object
- #nb_seconds ⇒ Object
- #shift(offset) ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(from, to) ⇒ Window
Returns a new instance of Window.
4 5 6 7 |
# File 'lib/time_win/window.rb', line 4 def initialize from, to @from, @to = from.to_time, to.to_time raise "Invalid time bounds from > to -- #{@from} > #{@to}" if !valid? end |
Instance Attribute Details
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/time_win/window.rb', line 3 def from @from end |
#to ⇒ Object (readonly)
Returns the value of attribute to.
3 4 5 |
# File 'lib/time_win/window.rb', line 3 def to @to end |
Instance Method Details
#nb_days ⇒ Object
25 26 27 |
# File 'lib/time_win/window.rb', line 25 def nb_days self.hours / 24 end |
#nb_hours ⇒ Object
21 22 23 |
# File 'lib/time_win/window.rb', line 21 def nb_hours self.minutes / 60 end |
#nb_minutes ⇒ Object
17 18 19 |
# File 'lib/time_win/window.rb', line 17 def nb_minutes self.seconds / 60 end |
#nb_seconds ⇒ Object
13 14 15 |
# File 'lib/time_win/window.rb', line 13 def nb_seconds @from - @to end |
#shift(offset) ⇒ Object
29 30 31 |
# File 'lib/time_win/window.rb', line 29 def shift offset Window.new(@from+offset, @to+offset) end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/time_win/window.rb', line 33 def to_s "[#{from} --> #{@to}]" end |
#valid? ⇒ Boolean
9 10 11 |
# File 'lib/time_win/window.rb', line 9 def valid? @from <= @to end |