Class: FileScheduler::TimeInterval

Inherits:
Object
  • Object
show all
Defined in:
lib/file_scheduler/time_interval.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to) ⇒ TimeInterval

Returns a new instance of TimeInterval.



8
9
10
# File 'lib/file_scheduler/time_interval.rb', line 8

def initialize(from, to)
  @from, @to = from, to
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



6
7
8
# File 'lib/file_scheduler/time_interval.rb', line 6

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/file_scheduler/time_interval.rb', line 6

def to
  @to
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
26
# File 'lib/file_scheduler/time_interval.rb', line 22

def ==(other)
  [:from, :to].all? do |attribute|
    other.respond_to?(attribute) and send(attribute) == other.send(attribute)
  end
end

#include?(time) ⇒ Boolean Also known as: matches?

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/file_scheduler/time_interval.rb', line 12

def include?(time)
  if from > to
    not time.between?(to, from)
  else
    time.between?(from, to)
  end
end

#inspectObject



32
33
34
# File 'lib/file_scheduler/time_interval.rb', line 32

def inspect
  to_s
end

#to_sObject



28
29
30
# File 'lib/file_scheduler/time_interval.rb', line 28

def to_s
  "#{from}-#{to}"
end