Class: KML::Kml

Inherits:
Object
  • Object
show all
Defined in:
lib/gpx_kml/kml.rb

Overview

Docu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Kml

Returns a new instance of Kml.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#file_nameObject (readonly)

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



27
28
29
# File 'lib/gpx_kml/kml.rb', line 27

def file_name
  @file_name
end

#pointsObject (readonly)

access data of the kml in readonly



30
31
32
# File 'lib/gpx_kml/kml.rb', line 30

def points
  @points
end

#points_lengthObject (readonly)

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



27
28
29
# File 'lib/gpx_kml/kml.rb', line 27

def points_length
  @points_length
end

#routesObject (readonly)

access data of the kml in readonly



30
31
32
# File 'lib/gpx_kml/kml.rb', line 30

def routes
  @routes
end

#routes_lengthObject (readonly)

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



27
28
29
# File 'lib/gpx_kml/kml.rb', line 27

def routes_length
  @routes_length
end

#tracksObject (readonly)

access data of the kml in readonly



30
31
32
# File 'lib/gpx_kml/kml.rb', line 30

def tracks
  @tracks
end

#tracks_lengthObject (readonly)

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



27
28
29
# File 'lib/gpx_kml/kml.rb', line 27

def tracks_length
  @tracks_length
end

Instance Method Details

#kml?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/gpx_kml/kml.rb', line 32

def kml?
  !@kml.nil? && !@kml.xpath('/xmlns:kml').empty?
end

#points?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/gpx_kml/kml.rb', line 52

def points?
  return true unless @kml.xpath('//xmlns:Point').empty?

  false
end

#routes?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/gpx_kml/kml.rb', line 40

def routes?
  return true unless @kml.xpath('//xmlns:LinearRing').empty?

  false
end

#tracks?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/gpx_kml/kml.rb', line 46

def tracks?
  return true unless @kml.xpath('//xmlns:LineString').empty?

  false
end

#valid?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/gpx_kml/kml.rb', line 36

def valid?
  kml? && (tracks? || routes? || points?)
end