rozi 0.0.7 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +255 -0
  3. data/lib/rozi.rb +6 -3
  4. data/lib/rozi/file_wrapper_base.rb +52 -0
  5. data/lib/rozi/module_functions.rb +19 -69
  6. data/lib/rozi/name_search.rb +176 -0
  7. data/lib/rozi/{ozi_functions.rb → shared.rb} +36 -9
  8. data/lib/rozi/tracks.rb +170 -0
  9. data/lib/rozi/version.rb +1 -1
  10. data/lib/rozi/waypoints.rb +315 -0
  11. data/test/rozi/file_wrapper_base_test.rb +29 -0
  12. data/test/rozi/module_functions_test.rb +11 -72
  13. data/test/rozi/name_search_test.rb +248 -0
  14. data/test/rozi/{ozi_functions_test.rb → shared_test.rb} +25 -5
  15. data/test/rozi/tracks_test.rb +105 -0
  16. data/test/rozi/waypoints_test.rb +268 -0
  17. data/test/test_data/expected_output_1.nst +6 -0
  18. data/{test_data → test/test_data}/expected_output_1.plt +9 -9
  19. data/{test_data → test/test_data}/expected_output_1.wpt +7 -7
  20. data/test/test_data/input_1.wpt +6 -0
  21. metadata +128 -34
  22. data/README.rdoc +0 -127
  23. data/lib/rozi/name.rb +0 -23
  24. data/lib/rozi/name_search_text.rb +0 -43
  25. data/lib/rozi/name_search_text_writer.rb +0 -71
  26. data/lib/rozi/track.rb +0 -67
  27. data/lib/rozi/track_point.rb +0 -39
  28. data/lib/rozi/track_writer.rb +0 -50
  29. data/lib/rozi/waypoint.rb +0 -90
  30. data/lib/rozi/waypoint_writer.rb +0 -38
  31. data/test/rozi/name_search_text_test.rb +0 -28
  32. data/test/rozi/name_search_text_writer_test.rb +0 -114
  33. data/test/rozi/track_point_test.rb +0 -32
  34. data/test/rozi/track_test.rb +0 -25
  35. data/test/rozi/track_writer_test.rb +0 -62
  36. data/test/rozi/waypoint_test.rb +0 -31
  37. data/test/rozi/waypoint_writer_test.rb +0 -60
@@ -1,38 +0,0 @@
1
-
2
- require "rozi/ozi_functions"
3
-
4
- module Rozi
5
-
6
- ##
7
- # This class writes a list of waypoints to a ".wpt" file that can be opened
8
- # by Ozi Explorer.
9
- #
10
- class WaypointWriter
11
-
12
- include OziFunctions
13
-
14
- def write(waypoints, file)
15
- file.write <<-TEXT.gsub(/^[ ]{8}/, "")
16
- OziExplorer Waypoint File Version 1.1
17
- WGS 84
18
- Reserved 2
19
-
20
- TEXT
21
-
22
- waypoints.each { |wpt|
23
- file.write(waypoint_to_text(wpt))
24
- file.write("\n")
25
- }
26
- end
27
-
28
- def waypoint_to_text(waypoint)
29
- wpt = waypoint.to_a()
30
- wpt.map! { |item| item.is_a?(String) ? escape_text(item) : item }
31
- wpt.map! { |item| item.nil? ? "" : item }
32
- wpt.map! { |item| item.is_a?(Float) ? item.round(6) : item }
33
-
34
- "%d,%s,%f,%f,%s,%d,1,%d,%d,%d,%s,%d,,,%d,%d,%d,%d" % wpt
35
- end
36
- end
37
-
38
- end
@@ -1,28 +0,0 @@
1
-
2
- module Rozi
3
-
4
- class NameSearchTextTest < Minitest::Test
5
-
6
- def setup
7
- @subject = NameSearchText.new
8
- end
9
-
10
- def test_add_name
11
- @subject << :foo
12
- @subject << :bar
13
-
14
- assert_equal [:foo, :bar], @subject.names
15
- end
16
-
17
- def test_set_datum
18
- @subject.datum = "WGS 84"
19
- @subject.datum = "Adindan"
20
-
21
- assert_raises(ArgumentError) {
22
- @subject.datum = "Foo bar"
23
- }
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,114 +0,0 @@
1
-
2
- require "stringio"
3
-
4
- module Rozi
5
-
6
- class NameSearchTextWriterTest < Minitest::Test
7
-
8
- def setup
9
- @subject = NameSearchTextWriter.new
10
- end
11
-
12
- def test_write_wgs_84
13
- expected_output = <<-NST.gsub(/ {8}/, "")
14
- ;Foo
15
- ;Bar
16
- ;Baz
17
- #1,,
18
- #2,WGS 84
19
- Oslo,Cities,,12.34,56.78
20
- Bergen,Cities,,23.45,67.89
21
- NST
22
-
23
- nst = NameSearchText.new
24
- nst.comment = "Foo\nBar\nBaz"
25
- nst << Name.new("Oslo", "Cities", nil, 12.34, 56.78)
26
- nst << Name.new("Bergen", "Cities", nil, 23.45, 67.89)
27
-
28
- output = write_to_string nst
29
-
30
- assert_equal expected_output, output
31
- end
32
-
33
- def test_write_wgs_utm
34
- expected_output = <<-NST.gsub(/ {8}/, "")
35
- #1,UTM,32V,N
36
- #2,Norsk
37
- Oslo,Cities,,12.34,56.78
38
- Bergen,Cities,33,23.45,67.89
39
- NST
40
-
41
- nst = NameSearchText.new
42
- nst.utm = true
43
- nst.utm_zone = "32V"
44
- nst.hemisphere = "N"
45
- nst.datum = "Norsk"
46
-
47
- nst << Name.new("Oslo", "Cities", nil, 12.34, 56.78)
48
- nst << Name.new("Bergen", "Cities", "33", 23.45, 67.89)
49
-
50
- output = write_to_string nst
51
-
52
- assert_equal expected_output, output
53
- end
54
-
55
- def test_construct_first_line_latlng
56
- nst = NameSearchText.new
57
- nst.utm = false
58
-
59
- assert_equal "#1,,", @subject.send(:construct_first_line, nst)
60
- end
61
-
62
- def test_construct_first_line_utm
63
- nst = NameSearchText.new
64
- nst.utm = true
65
- nst.utm_zone = "32"
66
- nst.hemisphere = "N"
67
-
68
- assert_equal "#1,UTM,32,N", @subject.send(:construct_first_line, nst)
69
-
70
- nst.hemisphere = nil
71
-
72
- assert_equal "#1,UTM,32", @subject.send(:construct_first_line, nst)
73
- end
74
-
75
- def test_construct_second_line
76
- nst = NameSearchText.new
77
- nst.datum = "Egypt"
78
-
79
- assert_equal "#2,Egypt", @subject.send(:construct_second_line, nst)
80
- end
81
-
82
- def test_name_to_line
83
- name = Rozi::Name.new "Foo", "Bar", nil, 12.34, 56.78
84
-
85
- expected_output = "Foo,Bar,,12.34,56.78"
86
- output = @subject.send :name_to_line, name
87
-
88
- assert_equal expected_output, output
89
- end
90
-
91
- def test_name_to_line_missing_components
92
- name1 = Rozi::Name.new nil, "Bar", nil, 12.34, 56.78
93
- name2 = Rozi::Name.new "Foo", "Bar", nil, nil, nil
94
- name3 = Rozi::Name.new nil, "Bar", nil, nil, nil
95
-
96
- [name1, name2, name3].each { |name|
97
- assert_raises(RuntimeError) {
98
- @subject.send(:name_to_line, name)
99
- }
100
- }
101
- end
102
-
103
- def write_to_string(nst)
104
- file = StringIO.new
105
-
106
- @subject.write(nst, file)
107
-
108
- file.rewind
109
- return file.read
110
- end
111
-
112
- end
113
-
114
- end
@@ -1,32 +0,0 @@
1
-
2
- module Rozi
3
-
4
- class TrackPointTest < Minitest::Test
5
- def test_initialize_defaults
6
- point = TrackPoint.new()
7
-
8
- TrackPoint::DEFAULTS.each_pair { |key, value|
9
- assert_equal value, point.send(key)
10
- }
11
- end
12
-
13
- def test_initialize_with_args
14
- attrs = {latitude: 123.45, longitude: 567.89, break: 1}
15
- point = TrackPoint.new(attrs)
16
-
17
- attrs.each_pair { |key, value|
18
- assert_equal value, point.send(key)
19
- }
20
- end
21
-
22
- def test_to_a
23
- point = TrackPoint.new(latitude: 123.45, longitude: 234.56)
24
-
25
- assert_equal(
26
- [123.45, 234.56, 0, -777, 0, "", ""],
27
- point.to_a()
28
- )
29
- end
30
- end
31
-
32
- end
@@ -1,25 +0,0 @@
1
-
2
- module Rozi
3
-
4
- class TrackTest < Minitest::Test
5
- def test_initialize_defaults
6
- t = Track.new()
7
-
8
- Track::DEFAULTS.each_pair { |key, value|
9
- assert_equal value, t.send(key)
10
- }
11
- end
12
-
13
- def test_initialize_with_args
14
- points = [:foo, :bar]
15
- attrs = {points: points, line_width: 2, type: 10}
16
-
17
- t = Track.new(attrs)
18
-
19
- attrs.each_pair { |key, value|
20
- assert_equal value, t.send(key)
21
- }
22
- end
23
- end
24
-
25
- end
@@ -1,62 +0,0 @@
1
-
2
- require "stringio"
3
-
4
- module Rozi
5
-
6
- class TrackWriterTest < Minitest::Test
7
- def test_write
8
- point1 = mock()
9
- point1.expects(:to_a).returns([12.34, 56.78, 0, -777, 0, "", ""])
10
-
11
- point2 = mock()
12
- point2.expects(:to_a).returns([23.45, 67.89, 0, -777, 0, "", ""])
13
-
14
- track = mock()
15
- track.expects(:attributes).returns([2, 255, "foo, bar", 1, 0, 0, 0])
16
- track.expects(:points).twice.returns([point1, point2])
17
-
18
- file = StringIO.new()
19
-
20
- subject = TrackWriter.new()
21
- subject.write(track, file)
22
-
23
- file.rewind()
24
-
25
- assert_equal(<<-TRACK, file.read())
26
- OziExplorer Track Point File Version 2.1
27
- WGS 84
28
- Altitude is in Feet
29
- Reserved 3
30
- 0,2,255,fooÑ bar,1,0,0,0
31
- 2
32
- 12.340000,56.780000,0,-777.0,0.0000000,,
33
- 23.450000,67.890000,0,-777.0,0.0000000,,
34
- TRACK
35
- end
36
-
37
- def test_track_attributes_to_text
38
- subject = TrackWriter.new()
39
-
40
- track = mock()
41
- track.expects(:attributes).returns([2, 0, "foo, bar", 1, 0, 0, 0])
42
-
43
- assert_equal(
44
- "0,2,0,fooÑ bar,1,0,0,0",
45
- subject.track_attributes_to_text(track)
46
- )
47
- end
48
-
49
- def test_track_point_to_text
50
- subject = TrackWriter.new()
51
-
52
- point = mock()
53
- point.expects(:to_a).returns([12.34, 56.78, 0, -777, 0, "", ""])
54
-
55
- assert_equal(
56
- " 12.340000,56.780000,0,-777.0,0.0000000,,",
57
- subject.track_point_to_text(point)
58
- )
59
- end
60
- end
61
-
62
- end
@@ -1,31 +0,0 @@
1
-
2
- module Rozi
3
-
4
- class WaypointTest < Minitest::Test
5
- def test_initialize
6
- wp = Waypoint.new(number: 5, name: "Test point")
7
-
8
- assert_equal "Test point", wp.name
9
- assert_equal 5, wp.number
10
-
11
- assert_raises(ArgumentError) {
12
- # Invalid attribute "foo".
13
- wp = Waypoint.new(foo: 123)
14
- }
15
- end
16
-
17
- def test_colors
18
- wp = Waypoint.new()
19
-
20
- wp.fg_color = "000000"
21
- assert_equal 0, wp.fg_color
22
-
23
- wp.fg_color = "ABCDEF"
24
- assert_equal 15715755, wp.fg_color
25
-
26
- wp.fg_color = 128
27
- assert_equal 128, wp.fg_color
28
- end
29
- end
30
-
31
- end
@@ -1,60 +0,0 @@
1
-
2
- module Rozi
3
-
4
- class WaypointWriterTest < Minitest::Test
5
- def setup
6
- @subject = WaypointWriter.new()
7
- end
8
-
9
- def test_write
10
- waypoints = []
11
- waypoints << Waypoint.new(
12
- name: "Test", latitude: 60.872030, longitude: 12.049732
13
- )
14
- waypoints << Waypoint.new(
15
- name: "Test 2", latitude: 61.872030, longitude: 12.049732
16
- )
17
- waypoints << Waypoint.new(
18
- name: "Test 3", latitude: 60.872030, longitude: 13.049732
19
- )
20
-
21
- file = StringIO.new()
22
-
23
- @subject.write(waypoints, file)
24
-
25
- expected_output = <<-TEXT.chomp
26
- OziExplorer Waypoint File Version 1.1
27
- WGS 84
28
- Reserved 2
29
-
30
- -1,Test,60.872030,12.049732,,3,1,4,0,65535,,0,,,-777,6,0,17
31
- -1,Test 2,61.872030,12.049732,,3,1,4,0,65535,,0,,,-777,6,0,17
32
- -1,Test 3,60.872030,13.049732,,3,1,4,0,65535,,0,,,-777,6,0,17
33
- TEXT
34
- end
35
-
36
- def test_waypoint_to_text
37
- wpt = Waypoint.new(name: "test")
38
-
39
- assert_equal(
40
- "-1,test,0.000000,0.000000,,0,1,3,0,65535,,0,,,-777,6,0,17",
41
- @subject.waypoint_to_text(wpt)
42
- )
43
-
44
- wpt = Waypoint.new(name: "test", symbol: 4)
45
-
46
- assert_equal(
47
- "-1,test,0.000000,0.000000,,4,1,3,0,65535,,0,,,-777,6,0,17",
48
- @subject.waypoint_to_text(wpt)
49
- )
50
-
51
- wpt = Waypoint.new(name: "test", description: "æøå, ÆØÅ")
52
-
53
- assert_equal(
54
- "-1,test,0.000000,0.000000,,0,1,3,0,65535,æøåÑ ÆØÅ,0,,,-777,6,0,17",
55
- @subject.waypoint_to_text(wpt)
56
- )
57
- end
58
- end
59
-
60
- end