Class: TimeWin::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/time_win/window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fromObject (readonly)

Returns the value of attribute from.



3
4
5
# File 'lib/time_win/window.rb', line 3

def from
  @from
end

#toObject (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_daysObject



25
26
27
# File 'lib/time_win/window.rb', line 25

def nb_days
  self.hours / 24
end

#nb_hoursObject



21
22
23
# File 'lib/time_win/window.rb', line 21

def nb_hours
  self.minutes / 60
end

#nb_minutesObject



17
18
19
# File 'lib/time_win/window.rb', line 17

def nb_minutes
  self.seconds / 60
end

#nb_secondsObject



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_sObject



33
34
35
# File 'lib/time_win/window.rb', line 33

def to_s
  "[#{from} --> #{@to}]"
end

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/time_win/window.rb', line 9

def valid?
  @from <= @to
end