Class: RubbishCollection::CollectionTime

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

Instance Method Summary collapse

Constructor Details

#initialize(pickup_type, time, resolution) ⇒ CollectionTime

Returns a new instance of CollectionTime.



168
169
170
171
172
# File 'lib/rubbish_collection.rb', line 168

def initialize pickup_type, time, resolution
  self.time = time
  self.resolution = resolution
  self.pickup_type = pickup_type
end

Instance Method Details

#<=>(other) ⇒ Object



190
191
192
# File 'lib/rubbish_collection.rb', line 190

def <=> other
  sort_key <=> other.sort_key
end

#human_dateObject



182
183
184
# File 'lib/rubbish_collection.rb', line 182

def human_date
  time.strftime '%A %d %B %Y'
end

#human_timeObject



174
175
176
177
178
179
180
# File 'lib/rubbish_collection.rb', line 174

def human_time
  return unless resolution > Resolution::DAY
  start_time = time
  end_time = time + resolution.step

  [ start_time, end_time ].map { |t| t.strftime('%l.%M%P').strip }.join(' to ')
end

#human_typeObject



186
187
188
# File 'lib/rubbish_collection.rb', line 186

def human_type
  pickup_type
end

#sort_keyObject



194
195
196
# File 'lib/rubbish_collection.rb', line 194

def sort_key
  [ time, resolution, pickup_type ]
end

#to_sObject



198
199
200
# File 'lib/rubbish_collection.rb', line 198

def to_s
  [ human_date, human_time ].compact.join(' from ') + " - #{human_type}"
end