Class: RubbishCollection::CollectionTime
- Inherits:
-
Object
- Object
- RubbishCollection::CollectionTime
- Defined in:
- lib/rubbish_collection.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #human_date ⇒ Object
- #human_time ⇒ Object
- #human_type ⇒ Object
-
#initialize(pickup_type, time, resolution) ⇒ CollectionTime
constructor
A new instance of CollectionTime.
- #sort_key ⇒ Object
- #to_s ⇒ Object
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_date ⇒ Object
182 183 184 |
# File 'lib/rubbish_collection.rb', line 182 def human_date time.strftime '%A %d %B %Y' end |
#human_time ⇒ Object
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_type ⇒ Object
186 187 188 |
# File 'lib/rubbish_collection.rb', line 186 def human_type pickup_type end |
#sort_key ⇒ Object
194 195 196 |
# File 'lib/rubbish_collection.rb', line 194 def sort_key [ time, resolution, pickup_type ] end |
#to_s ⇒ Object
198 199 200 |
# File 'lib/rubbish_collection.rb', line 198 def to_s [ human_date, human_time ].compact.join(' from ') + " - #{human_type}" end |