Class: RubbishCollection::Collection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pickup_type, schedule) ⇒ Collection

Returns a new instance of Collection.



131
132
133
134
# File 'lib/rubbish_collection.rb', line 131

def initialize pickup_type, schedule
  self.pickup_type = pickup_type
  self.schedule = schedule
end

Instance Attribute Details

#pickup_typeObject

Returns the value of attribute pickup_type.



125
126
127
# File 'lib/rubbish_collection.rb', line 125

def pickup_type
  @pickup_type
end

Instance Method Details

#realise(from, to) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/rubbish_collection.rb', line 136

def realise from, to
  times = []
  now = from
  resolution = schedule.resolution
  rem = now.to_i % resolution.step
  diff = resolution.step - rem
  now += diff
  while now < to
    if schedule.include? now
      time = CollectionTime.new pickup_type, now, resolution
      times << time
    end
    now += resolution.step
  end
  times
end

#to_sObject



153
154
155
# File 'lib/rubbish_collection.rb', line 153

def to_s
  [ pickup_type, schedule.to_s ].join ' - '
end