Class: RubbishCollection::Schedule

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resolution) ⇒ Schedule

Returns a new instance of Schedule.



92
93
94
# File 'lib/rubbish_collection.rb', line 92

def initialize resolution
  self.resolution = resolution
end

Instance Attribute Details

#resolutionObject

Returns the value of attribute resolution.



89
90
91
# File 'lib/rubbish_collection.rb', line 89

def resolution
  @resolution
end

Class Method Details

.day_of_week(day_name) ⇒ Object



96
97
98
99
100
# File 'lib/rubbish_collection.rb', line 96

def self.day_of_week day_name
  normalised_name = day_name[0,1].upcase + day_name[1..-1].downcase
  day_const = Runt.const_get normalised_name
  Runt::DIWeek.new day_const
end

.hour(hour) ⇒ Object



102
103
104
# File 'lib/rubbish_collection.rb', line 102

def self.hour hour
  Runt::REDay.new hour, 0, hour, 59, true
end

Instance Method Details

#add_rule(rule) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/rubbish_collection.rb', line 106

def add_rule rule
  if condition.nil?
    self.condition = rule
    return
  end
  self.condition = condition & rule
end

#include?(time) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
117
# File 'lib/rubbish_collection.rb', line 114

def include? time
  time_with_resolution = resolution.match_resolution time
  condition.include? time_with_resolution
end

#to_sObject



119
120
121
# File 'lib/rubbish_collection.rb', line 119

def to_s
  condition.to_s
end