/
cargo.rb
42 lines (35 loc) · 1.72 KB
/
cargo.rb
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
42
class Cargo
attr_accessor :tracking_id
attr_accessor :route_specification
attr_accessor :itinerary
attr_accessor :delivery
class InitializationError < RuntimeError; end
def initialize (tracking_id, route_specification)
raise InitializationError unless tracking_id && route_specification
@tracking_id = tracking_id
@route_specification = route_specification
@delivery = Delivery.new(@route_specification, @itinerary, nil)
end
# cf. https://github.com/SzymonPobiega/DDDSample.Net/blob/master/DDDSample-Vanilla/Domain/Cargo/Cargo.cs#L55
def specify_new_route (route_specification)
# TODO: add exception checking for invalid (null) values
@route_specification = route_specification
# TODO: Change to @delivery = Delivery.update_on_routing(@route_specification, @itinerary)
@delivery = Delivery.new(@route_specification, @itinerary, @delivery.last_handling_event)
end
# cf. https://github.com/SzymonPobiega/DDDSample.Net/blob/master/DDDSample-Vanilla/Domain/Cargo/Cargo.cs#L69
def assign_to_route (itinerary)
# TODO: add exception checking for invalid (null) values
@itinerary = itinerary
# TODO: Change to @delivery = Delivery.update_on_routing(@route_specification, @itinerary)
# @delivery = Delivery.new(@route_specification, @itinerary, @delivery.last_handling_event)
end
# cf. https://github.com/SzymonPobiega/DDDSample.Net/blob/master/DDDSample-Vanilla/Domain/Cargo/Cargo.cs#L83
def derive_delivery_progress (last_handling_event)
# TODO: Change to @delivery = Delivery.derived_from(@route_specification, @itinerary)?
@delivery = Delivery.new(@route_specification, @itinerary, last_handling_event)
end
def ==(other)
self.tracking_id == other.tracking_id
end
end