seeyoucup 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +29 -0
- data/lib/see_you_cup.rb +5 -0
- data/lib/see_you_cup/errors.rb +5 -0
- data/lib/see_you_cup/parser.rb +78 -0
- data/lib/see_you_cup/waypoint.rb +58 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c970e9e03cb3696ecaa0572a2c3d3d80060ba2b8c95819bcf937df1f2acfc350
|
4
|
+
data.tar.gz: dacac72a35f8d64216d1da69e586a4d7521197c92474fe389117577c8c6b0791
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47bb7f7b0be76b7f9eea7d3d30a7a469e8901db1aed172fcfa33e8756c77b188ffa53f57b25d76219df6221db3cd7166b32280414e34c0fde6120ed381d04cb6
|
7
|
+
data.tar.gz: 70aebf96bde325248f1e4547b96346a84c1bb58fdac6e020ec1732f83a4126ab4f44d7c2daa7f36adb662d146d8c7194a3e66c03f292dfe9d63ec0e2ffa8f098
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Ruby parser for SeeYou .cup files
|
2
|
+
|
3
|
+
# THIS IS A VERY EARLY VERSION
|
4
|
+
|
5
|
+
File format specs can be found [here](http://download.naviter.com/docs/CUP-file-format-description.pdf).
|
6
|
+
|
7
|
+
Example:
|
8
|
+
|
9
|
+
```
|
10
|
+
require 'seeyoucup'
|
11
|
+
|
12
|
+
waypoints = SeeYouCup::Parser.new("#{__dir__}/samples/basic.cup").parse
|
13
|
+
wp = waypoints.first
|
14
|
+
wp.name # String
|
15
|
+
wp.code # String
|
16
|
+
wp.country # String
|
17
|
+
wp.elev # String
|
18
|
+
wp.rwydir # String
|
19
|
+
wp.rwylen # String
|
20
|
+
wp.freq # String
|
21
|
+
wp.desc # String
|
22
|
+
wp.lat # Float
|
23
|
+
wp.lon # Float
|
24
|
+
```
|
25
|
+
|
26
|
+
Limitations:
|
27
|
+
|
28
|
+
* Only files containing ONLY `Waypoints` section are supported
|
29
|
+
* Files that combine `Waypoints` and `Tasks` have not been tested
|
data/lib/see_you_cup.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
module SeeYouCup
|
6
|
+
class Parser
|
7
|
+
def initialize(path)
|
8
|
+
raise FileNotFound unless File.exist?(path)
|
9
|
+
|
10
|
+
@buffer = StringIO.new(load_file(path), 'r')
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
res = []
|
15
|
+
res << read_waypoint(@buffer) until @buffer.eof?
|
16
|
+
res
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def read_waypoint(buffer)
|
22
|
+
# :name, :code, :country, :lat, :lon, :elev, :style, :rwydir, :rwylen, :freq, :desc
|
23
|
+
wp = Waypoint.new
|
24
|
+
wp.name = read_quoted_field(buffer)
|
25
|
+
wp.code = read_quoted_field(buffer)
|
26
|
+
wp.country = read_simple_field(buffer)
|
27
|
+
wp.lat = read_simple_field(buffer)
|
28
|
+
wp.lon = read_simple_field(buffer)
|
29
|
+
wp.elev = read_simple_field(buffer)
|
30
|
+
wp.style = read_simple_field(buffer)
|
31
|
+
wp.rwydir = read_simple_field(buffer)
|
32
|
+
wp.rwylen = read_simple_field(buffer)
|
33
|
+
wp.freq = read_simple_field(buffer)
|
34
|
+
wp.desc = read_quoted_field(buffer)
|
35
|
+
wp
|
36
|
+
end
|
37
|
+
|
38
|
+
def read_simple_field(buffer)
|
39
|
+
ret = String.new
|
40
|
+
while (char = buffer.getc)
|
41
|
+
break if char == ','
|
42
|
+
|
43
|
+
raise 'quote not allowed' if char == '"'
|
44
|
+
|
45
|
+
ret << char
|
46
|
+
end
|
47
|
+
ret
|
48
|
+
end
|
49
|
+
|
50
|
+
def read_quoted_field(buffer)
|
51
|
+
ret = String.new
|
52
|
+
quote_open = false
|
53
|
+
first = false
|
54
|
+
while (char = buffer.getc)
|
55
|
+
raise 'quote expected' if first && char != '"'
|
56
|
+
|
57
|
+
first = false
|
58
|
+
break if char == ',' && !quote_open
|
59
|
+
break if char == "\n" && !quote_open
|
60
|
+
|
61
|
+
if char == '"'
|
62
|
+
quote_open = !quote_open
|
63
|
+
else
|
64
|
+
ret << char
|
65
|
+
end
|
66
|
+
end
|
67
|
+
ret
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_file(path)
|
71
|
+
str = File.readlines(path).map(&:chomp)
|
72
|
+
# remove first line (column headers)
|
73
|
+
str.shift
|
74
|
+
# standardize line separator (in case \r was used before)
|
75
|
+
str.join("\n")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SeeYouCup
|
4
|
+
class Waypoint
|
5
|
+
STYLE_MAP = {
|
6
|
+
0 => 'Unknown',
|
7
|
+
1 => 'Waypoint',
|
8
|
+
2 => 'Airfield with grass surface runway',
|
9
|
+
3 => 'Outlanding',
|
10
|
+
4 => 'Gliding airfield',
|
11
|
+
5 => 'Airfield with solid surface runway',
|
12
|
+
6 => 'Mountain Pass',
|
13
|
+
7 => 'Mountain Top',
|
14
|
+
8 => 'Transmitter Mast',
|
15
|
+
9 => 'VOR',
|
16
|
+
10 => 'NDB',
|
17
|
+
11 => 'Cooling Tower',
|
18
|
+
12 => 'Dam',
|
19
|
+
13 => 'Tunnel',
|
20
|
+
14 => 'Bridge',
|
21
|
+
15 => 'Power Plant',
|
22
|
+
16 => 'Castle',
|
23
|
+
17 => 'Intersection'
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
attr_accessor :name, :code, :country, :elev, :rwydir, :rwylen, :freq, :desc
|
27
|
+
attr_reader :lat, :lon
|
28
|
+
|
29
|
+
def lon=(coord)
|
30
|
+
@lon = parse_coord(coord)
|
31
|
+
end
|
32
|
+
|
33
|
+
def lat=(coord)
|
34
|
+
@lat = parse_coord(coord)
|
35
|
+
end
|
36
|
+
|
37
|
+
def style=(style)
|
38
|
+
@style = style.to_i
|
39
|
+
end
|
40
|
+
|
41
|
+
def style
|
42
|
+
STYLE_MAP[@style]
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def parse_coord(coord)
|
48
|
+
return coord if coord.is_a?(Float)
|
49
|
+
|
50
|
+
coord = coord.upcase.strip.gsub(/^0/, '')
|
51
|
+
sign = %w[N E].include?(coord[-1]) ? 1 : -1
|
52
|
+
coord.chop!
|
53
|
+
deg = coord[0..1].to_f
|
54
|
+
min = coord[2..7].to_f
|
55
|
+
sign * (deg + min / 60)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seeyoucup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bartek Wilczek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email: bwilczek@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- README.md
|
76
|
+
- lib/see_you_cup.rb
|
77
|
+
- lib/see_you_cup/errors.rb
|
78
|
+
- lib/see_you_cup/parser.rb
|
79
|
+
- lib/see_you_cup/waypoint.rb
|
80
|
+
homepage: https://github.com/bwilczek/seeyoucup-rb
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.7.6
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: A library to work with SeeYou CUP files
|
104
|
+
test_files: []
|