diff options
| author | Zakaria BOUZIANE | 2014-12-15 16:39:39 +0100 | 
|---|---|---|
| committer | Zakaria BOUZIANE | 2014-12-15 16:39:39 +0100 | 
| commit | 4a38f7e0c6cf879fcd050b0b078cd488065a2202 (patch) | |
| tree | d88a092361faf2033f57e8611c4fd8d57e70ba65 /app/exporters | |
| parent | fbb5cb147d73e794e2a3abffe3cf0f0c21e5e6cd (diff) | |
| download | chouette-core-4a38f7e0c6cf879fcd050b0b078cd488065a2202.tar.bz2 | |
HUB Export : Adding ITL export
Diffstat (limited to 'app/exporters')
| -rw-r--r-- | app/exporters/chouette/hub/exporter.rb | 1 | ||||
| -rw-r--r-- | app/exporters/chouette/hub/itl_exporter.rb | 65 | 
2 files changed, 66 insertions, 0 deletions
| diff --git a/app/exporters/chouette/hub/exporter.rb b/app/exporters/chouette/hub/exporter.rb index 27ac4e7ee..110ad6b61 100644 --- a/app/exporters/chouette/hub/exporter.rb +++ b/app/exporters/chouette/hub/exporter.rb @@ -133,6 +133,7 @@ class Chouette::Hub::Exporter          if journey_patterns_exportable?            Chouette::Hub::RouteExporter.save(@routes, temp_dir, hub_export) +          Chouette::Hub::ItlExporter.save(@routes, temp_dir, hub_export)            Chouette::Hub::JourneyPatternExporter.save(@journey_patterns, temp_dir, hub_export)            Chouette::Hub::DirectionExporter.save(@journey_patterns, temp_dir, hub_export)          else diff --git a/app/exporters/chouette/hub/itl_exporter.rb b/app/exporters/chouette/hub/itl_exporter.rb new file mode 100644 index 000000000..8c281d965 --- /dev/null +++ b/app/exporters/chouette/hub/itl_exporter.rb @@ -0,0 +1,65 @@ +class Chouette::Hub::ItlExporter +  include ERB::Util +  attr_accessor :stop_point, :stop_area_id, :stop_area_code, :line_code, :sens, :order, :type, :identifier, :directory, :template +   +  def initialize(stop_point, sens, line, directory, index) +    @stop_point = stop_point +    @directory = directory +    @template = File.open('app/views/api/hub/itls.hub.erb' ){ |f| f.read } +    @line_code = line.objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') if line +    @sens = sens == 'A' ? 1 : 2 +    stop_area = stop_point.stop_area +    if stop_area +      @stop_area_code = stop_area.objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') +      @stop_area_id = stop_area.registration_number +    end +    @order = stop_point.position +    if stop_point.for_boarding == "forbidden" +      @type = 1 +    elsif stop_point.for_alighting == "forbidden" +      @type = 2 +    end +    @identifier = index +  end +   +  def render() +    ERB.new(@template).result(binding) +  end +   +  def hub_name +    "/ITL.TXT" +  end +   +  def self.save( routes, directory, hub_export) +    count = 0 +    routes.each do |route| +      for_boarding_stops = route.stop_points.where( :for_boarding => [ "forbidden" , "normal"] ).order(:position) +      if for_boarding_stops +        for_boarding_stops.each do |stop_point| +          count += 1 +          self.new( stop_point, route.wayback, route.line, directory, count ).tap do |specific_exporter| +            specific_exporter.save +          end +        end +      end +      for_alighting_stops = route.stop_points.where( :for_alighting => [ "forbidden" , "normal"] ).order(:position) +      if for_alighting_stops +        for_alighting_stops.each do |stop_point| +          count += 1 +          self.new( stop_point, route.wayback, route.line, directory, count ).tap do |specific_exporter| +            specific_exporter.save +          end +        end +      end +    end +    hub_export.log_messages.create( :severity => "ok", :key => "EXPORT|ITL_COUNT", :arguments => {"0" => count}) +  end +   +  def save +    File.open(directory + hub_name , "a:Windows_1252") do |f| +      f.write("ITL\u000D\u000A") if f.size == 0 +      f.write(render) +    end if stop_point.present? +  end +end + | 
