diff options
| author | Zog | 2018-03-05 12:00:29 +0100 |
|---|---|---|
| committer | Zog | 2018-03-05 12:00:29 +0100 |
| commit | a412f915c885f3bf2962d0b786ff864f1b0e120e (patch) | |
| tree | 3352d379f3d5c963f4382c374c6e78eea33cb2e1 /app | |
| parent | ea3de6035cdf9fbbcd92f51c90e5a2c5c3400cb3 (diff) | |
| download | chouette-core-a412f915c885f3bf2962d0b786ff864f1b0e120e.tar.bz2 | |
Refs #6068; Add some helpers in the models
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/chouette/journey_pattern.rb | 13 | ||||
| -rw-r--r-- | app/models/chouette/route.rb | 5 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 5 | ||||
| -rw-r--r-- | app/models/simple_exporter.rb | 2 |
4 files changed, 23 insertions, 2 deletions
diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index 830e985d9..10c8b5439 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -171,6 +171,19 @@ module Chouette full end + def distance_to stop + val = 0 + i = 0 + _end = stop_points.first + while _end != stop + i += 1 + _start = _end + _end = stop_points[i] + val += costs_between(_start, _end)[:distance] + end + val + end + def set_distances distances raise "inconsistent data: #{distances.count} values for #{stop_points.count} stops" unless distances.count == stop_points.count prev = distances[0].to_i diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 3729deb7d..445346745 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -191,6 +191,11 @@ module Chouette journey_pattern end + def generated_name + return "" unless stop_points.size > 1 + [stop_points.first, stop_points.last].map(&:name).join ' > ' + end + protected def self.vehicle_journeys_timeless(stop_point_id) diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 7170dd217..f58f97eee 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -390,9 +390,12 @@ module Chouette ActiveSupport::TimeZone[time_zone]&.utc_offset end - def country_name + def country return unless country_code country = ISO3166::Country[country_code] + end + + def country_name return unless country country.translations[I18n.locale.to_s] || country.name end diff --git a/app/models/simple_exporter.rb b/app/models/simple_exporter.rb index 9c12a4e02..fe0aa05b5 100644 --- a/app/models/simple_exporter.rb +++ b/app/models/simple_exporter.rb @@ -72,7 +72,7 @@ class SimpleExporter < SimpleInterface def map_item_to_rows item return [item] unless configuration.item_to_rows_mapping - configuration.item_to_rows_mapping.call(item).map {|row| CustomRow.new row } + configuration.item_to_rows_mapping.call(item).map {|row| row.is_a?(ActiveRecord::Base) ? row : CustomRow.new(row) } end def handle_item item |
