class KML::Kml

Docu

Attributes

file_name[R]

access in read only of the number of points, routes and tracks in the kml

points[R]

access data of the kml in readonly

points_length[R]

access in read only of the number of points, routes and tracks in the kml

routes[R]

access data of the kml in readonly

routes_length[R]

access in read only of the number of points, routes and tracks in the kml

tracks[R]

access data of the kml in readonly

tracks_length[R]

access in read only of the number of points, routes and tracks in the kml

Public Class Methods

new(file_path) click to toggle source
# File lib/gpx_kml/kml.rb, line 11
def initialize(file_path)
  return unless correct_path?(file_path) && (File.size(file_path) < 10_000_000)

  @kml = Nokogiri::XML(File.open(file_path))
  return unless valid?

  @file_name = File.basename(file_path)
  @tracks = _tracks
  @routes = _routes
  @points = _points
  @points_length = _points_length
  @routes_length = _routes_length
  @tracks_length = _tracks_length
end

Public Instance Methods

kml?() click to toggle source
# File lib/gpx_kml/kml.rb, line 32
def kml?
  !@kml.nil? && !@kml.xpath('/xmlns:kml').empty?
end
points?() click to toggle source
# File lib/gpx_kml/kml.rb, line 52
def points?
  return true unless @kml.xpath('//xmlns:Point').empty?

  false
end
routes?() click to toggle source
# File lib/gpx_kml/kml.rb, line 40
def routes?
  return true unless @kml.xpath('//xmlns:LinearRing').empty?

  false
end
tracks?() click to toggle source
# File lib/gpx_kml/kml.rb, line 46
def tracks?
  return true unless @kml.xpath('//xmlns:LineString').empty?

  false
end
valid?() click to toggle source
# File lib/gpx_kml/kml.rb, line 36
def valid?
  kml? && (tracks? || routes? || points?)
end

Private Instance Methods

_points() click to toggle source
# File lib/gpx_kml/kml.rb, line 80
def _points
  p = []
  @kml.xpath('//xmlns:Point').each_with_index do |pt, i|
    p[i] = KML::Point.new pt.xpath('./xmlns:coordinates/text()').to_s, self, pt
  end
  p
end
_points_length() click to toggle source
# File lib/gpx_kml/kml.rb, line 100
def _points_length
  return 0 if @points.nil?

  @points.length
end
_routes() click to toggle source
# File lib/gpx_kml/kml.rb, line 72
def _routes
  r = []
  @kml.xpath('//xmlns:LinearRing').each_with_index do |lr, i|
    r[i] = KML::Route.new lr
  end
  r
end
_routes_length() click to toggle source
# File lib/gpx_kml/kml.rb, line 94
def _routes_length
  return 0 if @routes.nil?

  @routes.length
end
_tracks() click to toggle source
# File lib/gpx_kml/kml.rb, line 64
def _tracks
  t = []
  @kml.xpath('//xmlns:LineString').each_with_index do |ls, i|
    t[i] = KML::Track.new ls
  end
  t
end
_tracks_length() click to toggle source
# File lib/gpx_kml/kml.rb, line 88
def _tracks_length
  return 0 if @tracks.nil?

  @tracks.length
end
correct_path?(path) click to toggle source
# File lib/gpx_kml/kml.rb, line 60
def correct_path?(path)
  path.instance_of?(String) && (path.end_with?('.kml') || path.end_with?('.xml') || !path.include?('.'))
end