Skip to content

Instantly share code, notes, and snippets.

@mudhappy
Created November 25, 2020 17:27
Show Gist options
  • Save mudhappy/d388c966f799b9b7a5f222290e069722 to your computer and use it in GitHub Desktop.
Save mudhappy/d388c966f799b9b7a5f222290e069722 to your computer and use it in GitHub Desktop.
Exportar info
packages = Package.actives.includes(:itineraries).includes(:activities);0
result = []
packages.each do |package|
res = []
res << package.name.gsub('|', '')
res << package.description.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish
res << package.starting_point.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish
res << package.includes.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish
res << package.not_includes.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish
res << package.stocks.try(:first).try(:stock_qty) || 14
res << package.notes.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish
res << package.viality_from.strftime("%d/%m/%Y")
res << package.viality_to.strftime("%d/%m/%Y")
res << package.days
res << package.nights
res << package.min_passenger
res << package.purchase_time
res << package.price
res << package.children_price
res << package.adult_foreigner_price
res << package.children_foreigner_price
res << package.housing_type || ""
res << package.housing_name || ""
res << package.housing_note.to_s.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish || ""
res << package.transport_type || ""
res << package.transport_name || ""
res << package.transport_note.to_s.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish || ""
3.times do |i|
if package.package_activities[i]
p_activity = package.package_activities[i]
res << p_activity.activity.name
if p_activity.mode == 'incluida'
res << 'Incluida'
else
res << 'No incluida'
end
else
res << ""
res << ""
end
end
3.times do |i|
if package.package_categories[i]
p_category = package.package_categories[i]
res << p_category.name
else
res << ""
end
end
3.times do |i|
if package.cities[i]
p_city = package.cities[i]
res << "#{p_city.name} (#{p_city.region.name}/#{p_city.name})"
else
res << ""
end
end
5.times do |i|
if package.itineraries[i]
p_itinerary = package.itineraries[i]
res << p_itinerary.name.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish
res << p_itinerary.description.gsub('|', ' ').gsub(/\s+/, ' ').gsub('&nbsp;', ' ').squish
else
res << ""
res << ""
end
end
3.times do |i|
if package.departures[i]
p_departure = package.departures[i]
res << p_departure.start
res << p_departure.end
else
res << ""
res << ""
end
end
res << package.language
res << package.turismoi_network ? 'true' : 'false'
res << package.saas_network ? 'true' : 'false'
result << res.join('|')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment