rozi 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rozi.rb +3 -0
- data/lib/rozi/module_functions.rb +73 -0
- data/lib/rozi/ozi_functions.rb +0 -23
- data/lib/rozi/track.rb +1 -1
- data/lib/rozi/track_writer.rb +16 -25
- data/lib/rozi/version.rb +1 -1
- data/lib/rozi/waypoint.rb +30 -30
- data/lib/rozi/waypoint_writer.rb +10 -20
- data/test/rozi/module_functions_test.rb +97 -0
- data/test/rozi/track_point_test.rb +0 -3
- data/test/rozi/track_test.rb +0 -2
- data/test/rozi/track_writer_test.rb +0 -2
- data/test/rozi/waypoint_test.rb +0 -10
- data/test/rozi/waypoint_writer_test.rb +4 -7
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c63cdef86599183152c63d7c23102fa868709ffb
|
4
|
+
data.tar.gz: f2990a902a99c2264eb013bc0d046625a924ed51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cfcc74f0d06872dda67073bd4ca1b3787e88ff9753f45c284781daf386a9c2b80f630c8229e79ea65073ad17356a40db1d54b4061dff5615d9d6497b716ab13
|
7
|
+
data.tar.gz: c713a377dc8004908d63b8b578c8366751a541039728894f983e6c06665e18472a7da53789619ee8e942c2230921438c9df8e76f447127d9e1db913d4fe2f8de
|
data/lib/rozi.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
module Rozi
|
3
|
+
|
4
|
+
module_function
|
5
|
+
|
6
|
+
##
|
7
|
+
# Opens a file handle with the correct settings for writing an Ozi Explorer
|
8
|
+
# file format.
|
9
|
+
#
|
10
|
+
# @overload open_file_for_writing(path)
|
11
|
+
#
|
12
|
+
# @param [String] path
|
13
|
+
# @return [File]
|
14
|
+
#
|
15
|
+
# @overload open_file_for_writing(path)
|
16
|
+
#
|
17
|
+
# Can be called with a block, just file +File.open+.
|
18
|
+
#
|
19
|
+
# @yieldparam [File] file
|
20
|
+
# @return [void]
|
21
|
+
#
|
22
|
+
def open_file_for_writing(path)
|
23
|
+
file = File.open(path, "w")
|
24
|
+
file.set_encoding("ISO-8859-1", "UTF-8", crlf_newline: true)
|
25
|
+
|
26
|
+
if block_given?
|
27
|
+
yield file
|
28
|
+
file.close
|
29
|
+
|
30
|
+
return nil
|
31
|
+
else
|
32
|
+
return file
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Writes an array of waypoints to a file.
|
38
|
+
#
|
39
|
+
# @see Rozi::WaypointWriter#write
|
40
|
+
#
|
41
|
+
def write_waypoints(waypoints, file)
|
42
|
+
@@wpt_writer ||= WaypointWriter.new
|
43
|
+
|
44
|
+
if file.is_a? String
|
45
|
+
open_file_for_writing(file) { |f|
|
46
|
+
@@wpt_writer.write(waypoints, f)
|
47
|
+
}
|
48
|
+
else
|
49
|
+
@@wpt_writer.write(waypoints, file)
|
50
|
+
end
|
51
|
+
|
52
|
+
return nil
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Writes a track to a file.
|
57
|
+
#
|
58
|
+
# @see Rozi::TrackWriter#write
|
59
|
+
#
|
60
|
+
def write_track(track, file)
|
61
|
+
@@track_writer ||= TrackWriter.new
|
62
|
+
|
63
|
+
if file.is_a? String
|
64
|
+
open_file_for_writing(file) { |f|
|
65
|
+
@@track_writer.write(track, f)
|
66
|
+
}
|
67
|
+
else
|
68
|
+
@@track_writer.write(track, file)
|
69
|
+
end
|
70
|
+
|
71
|
+
return nil
|
72
|
+
end
|
73
|
+
end
|
data/lib/rozi/ozi_functions.rb
CHANGED
@@ -34,29 +34,6 @@ module Rozi
|
|
34
34
|
|
35
35
|
color
|
36
36
|
end
|
37
|
-
|
38
|
-
##
|
39
|
-
# Opens a file handle with the correct settings for writing an Ozi
|
40
|
-
# Explorer file format.
|
41
|
-
#
|
42
|
-
# @param [String] path
|
43
|
-
# @return [File]
|
44
|
-
#
|
45
|
-
def open_file_for_writing(path)
|
46
|
-
if block_given?
|
47
|
-
file = File.open(path, "w") { |f|
|
48
|
-
f.set_encoding("ISO-8859-1", "UTF-8", crlf_newline: true)
|
49
|
-
yield f
|
50
|
-
}
|
51
|
-
|
52
|
-
return nil
|
53
|
-
else
|
54
|
-
file = File.open(path, "w")
|
55
|
-
file.set_encoding("ISO-8859-1", "UTF-8", crlf_newline: true)
|
56
|
-
|
57
|
-
return file
|
58
|
-
end
|
59
|
-
end
|
60
37
|
end
|
61
38
|
|
62
39
|
end
|
data/lib/rozi/track.rb
CHANGED
data/lib/rozi/track_writer.rb
CHANGED
@@ -8,38 +8,29 @@ module Rozi
|
|
8
8
|
include OziFunctions
|
9
9
|
|
10
10
|
##
|
11
|
-
# Writes the track to +file+ as an Ozi Explorer .
|
11
|
+
# Writes the track to +file+ as an Ozi Explorer track file. The file
|
12
|
+
# extension should be ".plt".
|
12
13
|
#
|
13
14
|
# @param [AddressKit::Ozi::Track] track
|
14
|
-
# @param [File, #write] file
|
15
|
+
# @param [File, String, #write] file
|
15
16
|
#
|
16
17
|
def write(track, file)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
TEXT
|
24
|
-
|
25
|
-
file.write(track_attributes_to_text(track))
|
26
|
-
file.write("\n")
|
18
|
+
file.write <<-TEXT.gsub(/^[ ]{8}/, "")
|
19
|
+
OziExplorer Track Point File Version 2.1
|
20
|
+
WGS 84
|
21
|
+
Altitude is in Feet
|
22
|
+
Reserved 3
|
23
|
+
TEXT
|
27
24
|
|
28
|
-
|
25
|
+
file.write(track_attributes_to_text(track))
|
26
|
+
file.write("\n")
|
29
27
|
|
30
|
-
|
31
|
-
file.write(track_point_to_text(point))
|
32
|
-
file.write("\n")
|
33
|
-
}
|
34
|
-
}
|
28
|
+
file.write(track.points.count.to_s() + "\n")
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
write_inner.call(track, file)
|
42
|
-
end
|
30
|
+
track.points.each { |point|
|
31
|
+
file.write(track_point_to_text(point))
|
32
|
+
file.write("\n")
|
33
|
+
}
|
43
34
|
end
|
44
35
|
|
45
36
|
def track_attributes_to_text(track)
|
data/lib/rozi/version.rb
CHANGED
data/lib/rozi/waypoint.rb
CHANGED
@@ -10,10 +10,19 @@ module Rozi
|
|
10
10
|
|
11
11
|
include OziFunctions
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
DISPLAY_FORMATS = {
|
14
|
+
:number_only => 0,
|
15
|
+
:name_only => 1,
|
16
|
+
:number_and_name => 2,
|
17
|
+
:name_with_dot => 3,
|
18
|
+
:name_with_symbol => 4,
|
19
|
+
:symbol_only => 5,
|
20
|
+
:comment_with_symbol => 6,
|
21
|
+
:man_overboard => 7,
|
22
|
+
:marker => 8
|
23
|
+
}
|
24
|
+
|
25
|
+
attr_accessor :number, :name, :latitude, :longitude, :date, :symbol,
|
17
26
|
:display_format, :description, :pointer_direction, :altitude,
|
18
27
|
:font_size, :font_style, :symbol_size
|
19
28
|
|
@@ -25,8 +34,8 @@ module Rozi
|
|
25
34
|
@latitude = 0.0
|
26
35
|
@longitude = 0.0
|
27
36
|
@date = nil
|
28
|
-
@symbol =
|
29
|
-
@display_format =
|
37
|
+
@symbol = 0
|
38
|
+
@display_format = :name_with_dot
|
30
39
|
@fg_color = 0
|
31
40
|
@bg_color = 65535
|
32
41
|
@description = ""
|
@@ -46,30 +55,21 @@ module Rozi
|
|
46
55
|
end
|
47
56
|
|
48
57
|
def to_a
|
49
|
-
[@number,
|
50
|
-
@
|
51
|
-
@
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
# the symbol as a integer.
|
65
|
-
#
|
66
|
-
def symbol(format=:symbol)
|
67
|
-
@@symbols_rev ||= SYMBOLS.invert()
|
68
|
-
|
69
|
-
case format
|
70
|
-
when :symbol then @@symbols_rev[@symbol]
|
71
|
-
when :number then @symbol
|
72
|
-
end
|
58
|
+
[@number,
|
59
|
+
@name,
|
60
|
+
@latitude,
|
61
|
+
@longitude,
|
62
|
+
@date,
|
63
|
+
@symbol,
|
64
|
+
DISPLAY_FORMATS[@display_format],
|
65
|
+
@fg_color,
|
66
|
+
@bg_color,
|
67
|
+
@description,
|
68
|
+
@pointer_direction,
|
69
|
+
@altitude,
|
70
|
+
@font_size,
|
71
|
+
@font_style,
|
72
|
+
@symbol_size]
|
73
73
|
end
|
74
74
|
|
75
75
|
##
|
data/lib/rozi/waypoint_writer.rb
CHANGED
@@ -12,27 +12,17 @@ module Rozi
|
|
12
12
|
include OziFunctions
|
13
13
|
|
14
14
|
def write(waypoints, file)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
TEXT
|
22
|
-
|
23
|
-
waypoints.each { |wpt|
|
24
|
-
file.write(waypoint_to_text(wpt))
|
25
|
-
file.write("\n")
|
26
|
-
}
|
27
|
-
}
|
15
|
+
file.write <<-TEXT.gsub(/^[ ]{8}/, "")
|
16
|
+
OziExplorer Waypoint File Version 1.1
|
17
|
+
WGS 84
|
18
|
+
Reserved 2
|
19
|
+
|
20
|
+
TEXT
|
28
21
|
|
29
|
-
|
30
|
-
file
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
write_inner.call(waypoints, file)
|
35
|
-
end
|
22
|
+
waypoints.each { |wpt|
|
23
|
+
file.write(waypoint_to_text(wpt))
|
24
|
+
file.write("\n")
|
25
|
+
}
|
36
26
|
end
|
37
27
|
|
38
28
|
def waypoint_to_text(waypoint)
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
require "tempfile"
|
3
|
+
|
4
|
+
module Rozi
|
5
|
+
class ModuleFunctionsTest < Minitest::Test
|
6
|
+
|
7
|
+
def test_open_file_for_writing
|
8
|
+
temp_file_path { |file_path|
|
9
|
+
file = Rozi.open_file_for_writing file_path
|
10
|
+
file.write("foo\nbar\næøå")
|
11
|
+
file.close
|
12
|
+
|
13
|
+
text = File.read(file_path, mode: "rb").force_encoding("ISO-8859-1")
|
14
|
+
|
15
|
+
assert_equal "foo\r\nbar\r\næøå".encode("ISO-8859-1"), text
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_open_file_for_writing_with_block
|
20
|
+
temp_file_path { |file_path|
|
21
|
+
f = nil
|
22
|
+
|
23
|
+
Rozi.open_file_for_writing(file_path) { |file|
|
24
|
+
assert_instance_of File, file
|
25
|
+
|
26
|
+
f = file
|
27
|
+
}
|
28
|
+
|
29
|
+
assert f.closed?
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_write_waypoints
|
34
|
+
waypoints = [
|
35
|
+
Rozi::Waypoint.new(
|
36
|
+
latitude: 59.91273, longitude: 10.74609, name: "OSLO"
|
37
|
+
),
|
38
|
+
Rozi::Waypoint.new(
|
39
|
+
latitude: 60.39358, longitude: 5.32476, name: "BERGEN"
|
40
|
+
),
|
41
|
+
Rozi::Waypoint.new(
|
42
|
+
latitude: 62.56749, longitude: 7.68709, name: "ÅNDALSNES"
|
43
|
+
)
|
44
|
+
]
|
45
|
+
|
46
|
+
temp_file_path { |file_path|
|
47
|
+
Rozi.write_waypoints(waypoints, file_path)
|
48
|
+
|
49
|
+
text = File.read(file_path, mode: "rb")
|
50
|
+
expected_output = read_test_file("expected_output_1.wpt")
|
51
|
+
|
52
|
+
assert_equal expected_output, text
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_write_track
|
57
|
+
track = Rozi::Track.new()
|
58
|
+
track << Rozi::TrackPoint.new(latitude: 59.91273, longitude: 10.74609)
|
59
|
+
track << Rozi::TrackPoint.new(latitude: 60.39358, longitude: 5.32476)
|
60
|
+
track << Rozi::TrackPoint.new(latitude: 62.56749, longitude: 7.68709)
|
61
|
+
|
62
|
+
temp_file_path { |file_path|
|
63
|
+
Rozi.write_track(track, file_path)
|
64
|
+
|
65
|
+
text = File.read(file_path, mode: "rb")
|
66
|
+
expected_output = read_test_file("expected_output_1.plt")
|
67
|
+
|
68
|
+
assert_equal expected_output, text
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def read_test_file(name)
|
75
|
+
path = File.join(Rozi::PROJECT_DIR, "test_data", name)
|
76
|
+
|
77
|
+
File.read(path, mode: "rb")
|
78
|
+
end
|
79
|
+
|
80
|
+
def temp_file_path(name="temp", suffix="")
|
81
|
+
path = Dir::Tmpname.make_tmpname(
|
82
|
+
"#{Dir::Tmpname.tmpdir}/rozi", "#{name}#{suffix}"
|
83
|
+
)
|
84
|
+
|
85
|
+
if block_given?
|
86
|
+
begin
|
87
|
+
yield path
|
88
|
+
ensure
|
89
|
+
File.unlink path if File.exist? path
|
90
|
+
end
|
91
|
+
else
|
92
|
+
return path
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
data/test/rozi/track_test.rb
CHANGED
data/test/rozi/waypoint_test.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
|
2
|
-
require "rozi/waypoint"
|
3
|
-
|
4
2
|
module Rozi
|
5
3
|
|
6
4
|
class WaypointTest < Minitest::Test
|
@@ -16,14 +14,6 @@ module Rozi
|
|
16
14
|
}
|
17
15
|
end
|
18
16
|
|
19
|
-
def test_symbol
|
20
|
-
wp = Waypoint.new()
|
21
|
-
wp.symbol = :house
|
22
|
-
|
23
|
-
assert_equal :house, wp.symbol
|
24
|
-
assert_equal 10, wp.symbol(:number)
|
25
|
-
end
|
26
|
-
|
27
17
|
def test_colors
|
28
18
|
wp = Waypoint.new()
|
29
19
|
|
@@ -1,7 +1,4 @@
|
|
1
1
|
|
2
|
-
require "rozi/waypoint_writer"
|
3
|
-
require "rozi/waypoint"
|
4
|
-
|
5
2
|
module Rozi
|
6
3
|
|
7
4
|
class WaypointWriterTest < Minitest::Test
|
@@ -40,21 +37,21 @@ Reserved 2
|
|
40
37
|
wpt = Waypoint.new(name: "test")
|
41
38
|
|
42
39
|
assert_equal(
|
43
|
-
"-1,test,0.000000,0.000000,,
|
40
|
+
"-1,test,0.000000,0.000000,,0,1,3,0,65535,,0,,,-777,6,0,17",
|
44
41
|
@subject.waypoint_to_text(wpt)
|
45
42
|
)
|
46
43
|
|
47
|
-
wpt = Waypoint.new(name: "test", symbol:
|
44
|
+
wpt = Waypoint.new(name: "test", symbol: 4)
|
48
45
|
|
49
46
|
assert_equal(
|
50
|
-
"-1,test,0.000000,0.000000,,
|
47
|
+
"-1,test,0.000000,0.000000,,4,1,3,0,65535,,0,,,-777,6,0,17",
|
51
48
|
@subject.waypoint_to_text(wpt)
|
52
49
|
)
|
53
50
|
|
54
51
|
wpt = Waypoint.new(name: "test", description: "æøå, ÆØÅ")
|
55
52
|
|
56
53
|
assert_equal(
|
57
|
-
"-1,test,0.000000,0.000000,,
|
54
|
+
"-1,test,0.000000,0.000000,,0,1,3,0,65535,æøåÑ ÆØÅ,0,,,-777,6,0,17",
|
58
55
|
@subject.waypoint_to_text(wpt)
|
59
56
|
)
|
60
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rozi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Sandven
|
@@ -19,6 +19,7 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- lib/rozi.rb
|
22
|
+
- lib/rozi/module_functions.rb
|
22
23
|
- lib/rozi/ozi_functions.rb
|
23
24
|
- lib/rozi/track.rb
|
24
25
|
- lib/rozi/track_point.rb
|
@@ -26,6 +27,7 @@ files:
|
|
26
27
|
- lib/rozi/version.rb
|
27
28
|
- lib/rozi/waypoint.rb
|
28
29
|
- lib/rozi/waypoint_writer.rb
|
30
|
+
- test/rozi/module_functions_test.rb
|
29
31
|
- test/rozi/track_point_test.rb
|
30
32
|
- test/rozi/track_test.rb
|
31
33
|
- test/rozi/track_writer_test.rb
|
@@ -61,3 +63,5 @@ test_files:
|
|
61
63
|
- test/rozi/track_writer_test.rb
|
62
64
|
- test/rozi/waypoint_writer_test.rb
|
63
65
|
- test/rozi/track_test.rb
|
66
|
+
- test/rozi/module_functions_test.rb
|
67
|
+
has_rdoc:
|