diff options
| author | Zakaria BOUZIANE | 2014-07-08 16:29:23 +0200 |
|---|---|---|
| committer | Zakaria BOUZIANE | 2014-07-08 16:29:23 +0200 |
| commit | dc541634dd463ade30b802e2a55f1fe27a8dd892 (patch) | |
| tree | 794253d45b387dbc81c4ba4b2d5a03d8353d9a18 /app/exporters | |
| parent | a77d67e7807f90ea24e96b5c1a9e6bbb290170b0 (diff) | |
| download | chouette-core-dc541634dd463ade30b802e2a55f1fe27a8dd892.tar.bz2 | |
HUB Export: company and network
Diffstat (limited to 'app/exporters')
| -rw-r--r-- | app/exporters/chouette/hub/company_exporter.rb | 35 | ||||
| -rw-r--r-- | app/exporters/chouette/hub/connection_link_exporter.rb | 2 | ||||
| -rw-r--r-- | app/exporters/chouette/hub/exporter.rb | 16 | ||||
| -rw-r--r-- | app/exporters/chouette/hub/network_exporter.rb | 35 |
4 files changed, 81 insertions, 7 deletions
diff --git a/app/exporters/chouette/hub/company_exporter.rb b/app/exporters/chouette/hub/company_exporter.rb new file mode 100644 index 000000000..eb530d6d4 --- /dev/null +++ b/app/exporters/chouette/hub/company_exporter.rb @@ -0,0 +1,35 @@ +class Chouette::Hub::CompanyExporter + include ERB::Util + attr_accessor :company, :directory, :template + + def initialize(company, directory) + @company = company + @directory = directory + @template = File.open('app/views/api/hub/transporteur/show.hub.erb' ){ |f| f.read } + end + + def render() + ERB.new(@template).result(binding) + end + + def hub_name + "/TRANSPORTEUR.TXT" + end + + def self.save( companies, directory, hub_export) + companies.each do |company| + self.new( company, directory).tap do |specific_exporter| + specific_exporter.save + end + end + hub_export.log_messages.create( :severity => "ok", :key => "EXPORT|COMPANY_COUNT", :arguments => {"0" => companies.size}) + end + + def save + File.open(directory + hub_name , "a") do |f| + f.write("TRANSPORTEUR\n") if f.size == 0 + f.write(render) + end if company.present? + end +end + diff --git a/app/exporters/chouette/hub/connection_link_exporter.rb b/app/exporters/chouette/hub/connection_link_exporter.rb index b3be19396..793da52bd 100644 --- a/app/exporters/chouette/hub/connection_link_exporter.rb +++ b/app/exporters/chouette/hub/connection_link_exporter.rb @@ -1,4 +1,4 @@ -class Chouette::Hub::Connection_LinkExporter +class Chouette::Hub::ConnectionLinkExporter include ERB::Util attr_accessor :connection_link, :directory, :template diff --git a/app/exporters/chouette/hub/exporter.rb b/app/exporters/chouette/hub/exporter.rb index 4b846fee0..5f1a1508f 100644 --- a/app/exporters/chouette/hub/exporter.rb +++ b/app/exporters/chouette/hub/exporter.rb @@ -118,7 +118,7 @@ class Chouette::Hub::Exporter Chouette::Hub::CommercialStopAreaExporter.save(commercial_stop_areas, temp_dir, hub_export) Chouette::Hub::PhysicalStopAreaExporter.save(physical_stop_areas, temp_dir, hub_export) - connection_links = Chouette::ConnectionLink.where( "deprture_id IN (?) AND arrival_id IN (?)", (physical_stop_areas.map(&:id) + commercial_stop_areas.map(&:id)), (physical_stop_areas.map(&:id) + commercial_stop_areas.map(&:id)) ) + connection_links = Chouette::ConnectionLink.where( "departure_id IN (?) AND arrival_id IN (?)", (physical_stop_areas.map(&:id) + commercial_stop_areas.map(&:id)), (physical_stop_areas.map(&:id) + commercial_stop_areas.map(&:id)) ) Chouette::Hub::ConnectionLinkExporter.save(connection_links, temp_dir, hub_export) @@ -130,15 +130,19 @@ class Chouette::Hub::Exporter if lines_exportable? Chouette::Hub::LineExporter.save(@lines, temp_dir, hub_export) + networks = Chouette::Network.where( :id => @lines.map(&:network_id)) + companies = Chouette::Network.where( :id => @lines.map(&:company_id)) + Chouette::Hub::NetworkExporter.save(networks, temp_dir, hub_export) + Chouette::Hub::CompanyExporter.save(companies, temp_dir, hub_export) else log_overflow_warning(Chouette::Line) end - if routes_exportable? - #Chouette::Hub::RouteExporter.save( routes, temp_dir, hub_export) - else - log_overflow_warning(Chouette::Route) if lines_exportable? - end + #if routes_exportable? + # Chouette::Hub::RouteExporter.save( routes, temp_dir, hub_export) + #else + # log_overflow_warning(Chouette::Route) if lines_exportable? + #end # if too many lines # there may be too many stop_areas diff --git a/app/exporters/chouette/hub/network_exporter.rb b/app/exporters/chouette/hub/network_exporter.rb new file mode 100644 index 000000000..d59cd5fd3 --- /dev/null +++ b/app/exporters/chouette/hub/network_exporter.rb @@ -0,0 +1,35 @@ +class Chouette::Hub::NetworkExporter + include ERB::Util + attr_accessor :network, :directory, :template + + def initialize(network, directory) + @network = network + @directory = directory + @template = File.open('app/views/api/hub/reseau/show.hub.erb' ){ |f| f.read } + end + + def render() + ERB.new(@template).result(binding) + end + + def hub_name + "/RESEAU.TXT" + end + + def self.save( networks, directory, hub_export) + networks.each do |network| + self.new( network, directory).tap do |specific_exporter| + specific_exporter.save + end + end + hub_export.log_messages.create( :severity => "ok", :key => "EXPORT|NETWORK_COUNT", :arguments => {"0" => networks.size}) + end + + def save + File.open(directory + hub_name , "a") do |f| + f.write("RESEAU\n") if f.size == 0 + f.write(render) + end if network.present? + end +end + |
