Created
September 12, 2013 18:23
-
-
Save hayduke19us/6541794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "Nokogiri" | |
require 'active_support/core_ext/hash/conversions' | |
puts "type in the full path to the file to be parsed." | |
file = gets.chomp.to_s | |
# Grab the file that needs to be parsed | |
f = File.open(file) | |
# Parse the XML | |
doc = Nokogiri::XML(f) | |
# Create a new hash of the data | |
doc = Hash.from_xml(doc.to_s) | |
# Create an array of the waypoint data | |
waypoints = doc["gpx"]["wpt"] | |
# Profit! | |
puts "=-=-=-=-=-=-=-=-=" | |
puts "Fish are here =>" | |
puts "\n" | |
waypoints.each do |wpt| | |
puts "Waypoint: " + wpt["name"] | |
puts "Coords: " + wpt["lat"] + ", " + wpt["lon"] | |
end | |
puts "\n" | |
puts "=-=-=-=-=-=-=-=-=" | |
new_page = Nokogiri::XML::Builder.new do |xml| | |
xml.gpx{ | |
xml.version "1.1" | |
xml.creator "Directional_fish" | |
waypoints.each do |line| | |
xml.wpt(:lat => line["lat"], :lon => line["lon"]) { | |
xml.name "test" | |
xml.sym "dot" | |
} | |
end | |
xml.rte{ | |
xml.name "test" | |
xml.desc | |
xml.number | |
} | |
} | |
end | |
File.open("/Users/hayduke19us/Documents/test.gpx", 'w') do |write| | |
write.puts new_page.to_xml | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment