Class: LZRTag::Map::MyMapsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/lzrtag/map/myMaps_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ MyMapsParser

Returns a new instance of MyMapsParser.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lzrtag/map/myMaps_parser.rb', line 13

def initialize(filename)
	@xmlStructure = XmlSimple.xml_in(filename)["Document"][0];

	@styles = Hash.new();
	_fetch_styles();

	@polygons = Hash.new();
	@polygons[""] = _fetch_polygons();

	@points = Hash.new();
	@points[""] = _fetch_marks();

	if(folders = @xmlStructure["Folder"])
		folders.each do |folder|
			@polygons[folder["name"][0]] = _fetch_polygons(folder)
			@points[folder["name"][0]] = _fetch_marks(folder);
		end
	end
end

Instance Attribute Details

#pointsObject

Returns the value of attribute points.



11
12
13
# File 'lib/lzrtag/map/myMaps_parser.rb', line 11

def points
  @points
end

#polygonsObject

Returns the value of attribute polygons.



10
11
12
# File 'lib/lzrtag/map/myMaps_parser.rb', line 10

def polygons
  @polygons
end

#stylesObject

Returns the value of attribute styles.



9
10
11
# File 'lib/lzrtag/map/myMaps_parser.rb', line 9

def styles
  @styles
end

Instance Method Details

#_fetch_marks(folder = nil) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/lzrtag/map/myMaps_parser.rb', line 93

def _fetch_marks(folder = nil)
	folder ||= @xmlStructure;

	outPoints = Array.new();
	return outPoints unless(placemarks = folder["Placemark"])

	placemarks.each do |pmark|
		next unless pmark["Point"];

		outPoint = Hash.new();
		outPoint[:name] = pmark["name"][0];
		outPoint[:description] = (pmark["description"] || [""])[0];

		outPoint[:description].split("<br>").each do |tag|
			if(tag =~ /([^:]*):([^:]*)/)
				outPoint[:arguments][$1] = $2;
			end
		end

		outPoint[:point] = pmark["Point"][0]["coordinates"][0].gsub(/\s/, "").split(",")[0..1];

		outPoints << outPoint
	end

	return outPoints
end

#generate_zones(zoneSet = "") ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/lzrtag/map/myMaps_parser.rb', line 120

def generate_zones(zoneSet = "")
	if(zoneSet.is_a? String)
		zoneSet = @polygons[zoneSet];
	end

	zoneSet = [zoneSet].flatten;

	outZones = Array.new();
	zoneSet.each do |rawZone|
		outZones << Zone.from_raw_zone(rawZone);
	end

	return outZones;
end