aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/stop_areas_to_way_costs_converter.rb21
-rw-r--r--lib/way_cost.rb7
2 files changed, 25 insertions, 3 deletions
diff --git a/lib/stop_areas_to_way_costs_converter.rb b/lib/stop_areas_to_way_costs_converter.rb
new file mode 100644
index 000000000..c6a00d31b
--- /dev/null
+++ b/lib/stop_areas_to_way_costs_converter.rb
@@ -0,0 +1,21 @@
+class StopAreasToWayCostsConverter
+ def initialize(stop_areas)
+ @stop_areas = stop_areas
+ end
+
+ def convert
+ @stop_areas.each_cons(2).map do |stop_area_pair|
+ WayCost.new(
+ departure: Geokit::LatLng.new(
+ stop_area_pair[0].latitude,
+ stop_area_pair[0].longitude
+ ),
+ arrival: Geokit::LatLng.new(
+ stop_area_pair[1].latitude,
+ stop_area_pair[1].longitude
+ ),
+ id: "#{stop_area_pair[0].id}-#{stop_area_pair[1].id}"
+ )
+ end
+ end
+end
diff --git a/lib/way_cost.rb b/lib/way_cost.rb
index 5de64177f..9f860308c 100644
--- a/lib/way_cost.rb
+++ b/lib/way_cost.rb
@@ -1,5 +1,5 @@
class WayCost
- attr_reader :departure, :arrival
+ attr_reader :departure, :arrival, :id
attr_accessor :distance, :time
def initialize(
@@ -7,7 +7,7 @@ class WayCost
arrival:,
distance: nil,
time: nil,
- id: nil # TODO: calculate ID automatically
+ id: nil
)
@departure = departure
@arrival = arrival
@@ -21,6 +21,7 @@ class WayCost
@departure == other.departure &&
@arrival == other.arrival &&
@distance == other.distance &&
- @time == other.time
+ @time == other.time &&
+ @id == other.id
end
end