|
14 | 14 |
|
15 | 15 | shelters = JSON.parse(File.read(shelters_file)) |
16 | 16 |
|
17 | | -printf("%s\r\n",'<?xml version="1.0" encoding="UTF-8"?>') |
18 | | -printf("%s\r\n",'<kml xmlns="http://earth.google.com/kml/2.0">') |
19 | | -printf("<Document>\r\n") |
20 | | -printf("<name>Shelters in Denmark.</name>\r\n") |
| 17 | +printf("%s\n",'<?xml version="1.0" encoding="UTF-8"?>') |
| 18 | +printf("%s\n",'<kml xmlns="http://earth.google.com/kml/2.0">') |
| 19 | +printf("<Document>\n") |
| 20 | +printf("<name>Shelters in Denmark.</name>\n") |
21 | 21 | shelters.each do |shelter| |
22 | | - printf("<Placemark>\r\n<styleUrl>#placemark-orange</styleUrl>\r\n<name>%s</name>\r\n<description>", shelter['name'].gsub(/"/, '').gsub(/&/, '&')) |
| 22 | + printf("<Placemark>\n<name>%s</name>\n<description>\n", shelter['name'].gsub(/"/, '').gsub(/&/, '&')) |
23 | 23 | printf("Address: %s, ", shelter['address']) unless ( shelter['address'] == '' ) |
24 | | - counter = 1 |
25 | | - shelter['features'].each do |x| |
26 | | - case x |
27 | | - when 9002 |
28 | | - printf("Has WC") |
29 | | - when 9001 |
30 | | - printf("Has Primitive Toilet") |
31 | | - when 9000 |
32 | | - printf("No information on toilet") |
| 24 | + |
| 25 | + # Process the features. Documented at https://shelterapp.dk/api/features/ |
| 26 | + shelter['features'].each do |feature| |
| 27 | + case feature |
| 28 | + when 0 |
| 29 | + printf("Putting up a tent is allowed.") |
33 | 30 | when 1 |
34 | | - printf("Is accessible for disabled") |
| 31 | + printf("Is accessible for disabled.") |
35 | 32 | when 6 |
36 | | - printf("Has access to drinking water") |
| 33 | + printf("Has access to drinking water.") |
37 | 34 | when 9 |
38 | | - printf("Has shelter") |
| 35 | + printf("Has shelter.") |
39 | 36 | when 10 |
40 | | - printf("Has fireplace") |
| 37 | + printf("Has fireplace.") |
41 | 38 | when 11 |
42 | | - printf("Is accessible via Cano") |
| 39 | + printf("Is accessible via Cano.") |
43 | 40 | when 12 |
44 | | - printf("Has shower facilities") |
| 41 | + printf("Has shower facilities.") |
45 | 42 | when 13 |
46 | | - printf("Dogs allowed") |
| 43 | + printf("Dogs allowed.") |
47 | 44 | when 14 |
48 | | - printf("Horses allowed") |
| 45 | + printf("Horses allowed.") |
49 | 46 | when 15 |
50 | | - printf("Accessible with baby stroller") |
| 47 | + printf("Accessible with baby stroller.") |
| 48 | + when 3081 |
| 49 | + printf("Has space for hammock.") |
| 50 | + when 9000 |
| 51 | + printf("No information on toilet.") |
| 52 | + when 9001 |
| 53 | + printf("Has Primitive Toilet.") |
| 54 | + when 9002 |
| 55 | + printf("Has WC.") |
| 56 | + when 9003 |
| 57 | + printf("Is bookable.") |
| 58 | + when 9004 |
| 59 | + printf("Is paid.") |
| 60 | + when 9005 |
| 61 | + printf("There are photo's in the app.") |
51 | 62 | else |
52 | | - printf("This shelter has an unknown feature: %i. That's exciting! What will it be?", x) |
| 63 | + printf("This shelter has an unknown feature: %i. That's exciting! What will it be?", feature) |
53 | 64 | end |
54 | | - printf(", ") if ( counter < shelter['features'].count ) |
55 | | - counter += 1 |
| 65 | + printf("\n") |
56 | 66 | end |
57 | | - printf("Booking possible") if ( shelter['booking'] == 1 ) |
58 | | - printf("</description>\r\n<Point><coordinates>%s,%s,0</coordinates></Point>\r\n</Placemark>\r\n", shelter['longitude'], shelter['latitude']) |
| 67 | + # Default the colour is yellow |
| 68 | + icon_colour = "yellow" |
| 69 | + |
| 70 | + # Green if only a tent is allowed |
| 71 | + icon_colour = "green" if ( shelter['features'].include?(0) ) |
| 72 | + |
| 73 | + # Orange if there is a shelter and a tent is allowed |
| 74 | + icon_colour = "orange" if ( shelter['features'].include?(9) and shelter['features'].include?(0) ) |
| 75 | + |
| 76 | + # Pink if there is a shelter and a tent is allowed and it has water and a toilet |
| 77 | + icon_colour = "pink" if ( shelter['features'].include?(9) and shelter['features'].include?(0) and shelter['features'].include?(6) and ( shelter['features'].include?(9001) or shelter['features'].include?(9002) ) ) |
| 78 | + |
| 79 | + # Blue if there is a shelter and NO tent is explicitly allowed |
| 80 | + icon_colour = "blue" if ( shelter['features'].include?(9) and !shelter['features'].include?(0) ) |
| 81 | + |
| 82 | + # Purple if it's a paid shelterplace OR reservation is possible |
| 83 | + icon_colour = "purple" if ( shelter['features'].include?(9004) or shelter['features'].include?(9003) ) |
| 84 | + |
| 85 | + # Red if it's a paid shelterplace with reservation |
| 86 | + icon_colour = "red" if ( shelter['features'].include?(9004) and shelter['features'].include?(9003) ) |
| 87 | + |
| 88 | + printf("</description>\n<Point><coordinates>%s,%s,0</coordinates>\n</Point>\n<styleUrl>#placemark-%s</styleUrl>\n</Placemark>\n", shelter['longitude'], shelter['latitude'], icon_colour) |
59 | 89 | end |
60 | | -printf("%s\r\n%s", '</Document>', '</kml>') |
| 90 | +printf("%s\n%s", '</Document>', '</kml>') |
0 commit comments