From d1661c9504876812d64ba3b8182612737f04900c Mon Sep 17 00:00:00 2001 From: Zakaria BOUZIANE Date: Mon, 15 Dec 2014 10:05:03 +0100 Subject: HUB Export: calendars export refinement --- app/exporters/chouette/hub/time_table_exporter.rb | 23 ++++++++++++++--------- app/views/api/hub/periodes.hub.erb | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/exporters/chouette/hub/time_table_exporter.rb b/app/exporters/chouette/hub/time_table_exporter.rb index 2a48586e3..98fac8fef 100644 --- a/app/exporters/chouette/hub/time_table_exporter.rb +++ b/app/exporters/chouette/hub/time_table_exporter.rb @@ -1,15 +1,19 @@ class Chouette::Hub::TimeTableExporter include ERB::Util - attr_accessor :time_table, :directory, :template, :start_date, :end_date, :identifier + attr_accessor :directory, :template, :time_table, :code, :comment, :start_date, :end_date, :calendar, :identifier - def initialize(time_table, directory, identifier) + def initialize(time_table, directory, index) @time_table = time_table @directory = directory - @identifier = identifier @template = File.open('app/views/api/hub/periodes.hub.erb' ){ |f| f.read } + + @code = time_table.objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') + @comment = time_table.comment.encode(Encoding::Windows_1252) if time_table.comment + @start_date = time_table.start_date.strftime("%d/%m/%Y") + @end_date = time_table.end_date.strftime("%d/%m/%Y") @calendar = "" - s_date = @time_table.start_date - e_date = @time_table.end_date + s_date = time_table.start_date + e_date = time_table.end_date while s_date <= e_date if time_table.include_day?(s_date) @calendar += "1" @@ -18,6 +22,7 @@ class Chouette::Hub::TimeTableExporter end s_date = s_date.next_day end + @identifier = index end def render() @@ -29,16 +34,16 @@ class Chouette::Hub::TimeTableExporter end def self.save(time_tables, directory, hub_export) - identifier = 1 + index = 1 time_tables.each do |time_table| - self.new(time_table, directory, identifier).tap do |specific_exporter| + self.new(time_table, directory, index).tap do |specific_exporter| specific_exporter.save - identifier += 1 + index += 1 end end hub_export.log_messages.create( :severity => "ok", :key => "EXPORT|TIME_TABLE_COUNT", :arguments => {"0" => time_tables.size}) end - + def save File.open(directory + hub_name , "a:Windows_1252") do |f| f.write("PERIODE\u000D\u000A") if f.size == 0 diff --git a/app/views/api/hub/periodes.hub.erb b/app/views/api/hub/periodes.hub.erb index 0eefda438..64737c17d 100644 --- a/app/views/api/hub/periodes.hub.erb +++ b/app/views/api/hub/periodes.hub.erb @@ -1 +1 @@ -<%= Chouette::TimeTable.find(@time_table.id).objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') %>;<%= @time_table.comment.encode(Encoding::Windows_1252) if @time_table.comment %>;<%= @time_table.start_date.strftime("%d/%m/%Y") %>;<%= @time_table.end_date.strftime("%d/%m/%Y") %>;<%= @calendar %>;<%= @identifier %><%= "\u000D\u000A" %> \ No newline at end of file +<%= @code %>;<%= @comment %>;<%= @start_date %>;<%= @end_date %>;<%= @calendar %>;<%= @identifier %><%= "\u000D\u000A" %> \ No newline at end of file -- cgit v1.2.3