-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.rb
More file actions
41 lines (31 loc) · 854 Bytes
/
route.rb
File metadata and controls
41 lines (31 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require_relative 'station'
class Route
extend Accessors
include InstanceCounter
include Validation
attr_reader :name, :stations
strong_attr_accessor :source, Station
strong_attr_accessor :destination, Station
validate :source, :presence
validate :destination, :presence
def initialize(source, destination)
@source = source
@destination = destination
@stations = [@source, @destination]
validate!
@name = "#{@source.name.capitalize} - #{@destination.name.capitalize}"
register_instance
end
def add(station)
@stations.insert(-2, station)
end
def remove(station)
first_last = [@stations.first, @stations.last]
@stations.delete(station) if first_last.none?(station)
end
def route
@stations.each { |station| puts station }
end
private
attr_reader :source, :destination
end