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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 025afb43aa2addc11320d73c12fb94089283b198
4
- data.tar.gz: f8a5f17bcbcd4a215dce4f661069543819d856d0
3
+ metadata.gz: c63cdef86599183152c63d7c23102fa868709ffb
4
+ data.tar.gz: f2990a902a99c2264eb013bc0d046625a924ed51
5
5
  SHA512:
6
- metadata.gz: ffc45b19f22f0391335bc8cc3a3e72c64f6a75d4f6f890fee5dd2d004fbd03c81251052faa526f89088f261bea56243a940aced00312fbbe2178a5e3675b38e5
7
- data.tar.gz: 83241e9f3a10dea99775a32192c51c64fa1d4afc05a64ab3a7ee19889bb614468ff7dc27a147a7069f64d896481e83be092eafcd2907b8228cf43439afd52a44
6
+ metadata.gz: 9cfcc74f0d06872dda67073bd4ca1b3787e88ff9753f45c284781daf386a9c2b80f630c8229e79ea65073ad17356a40db1d54b4061dff5615d9d6497b716ab13
7
+ data.tar.gz: c713a377dc8004908d63b8b578c8366751a541039728894f983e6c06665e18472a7da53789619ee8e942c2230921438c9df8e76f447127d9e1db913d4fe2f8de
@@ -1,5 +1,8 @@
1
1
 
2
2
  module Rozi
3
+
4
+ PROJECT_DIR = File.expand_path("../", File.dirname(__FILE__))
5
+
3
6
  ##
4
7
  # Loads all ruby files under lib/rozi. Called automatically when requiring
5
8
  # "rozi.rb".
@@ -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
@@ -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
@@ -30,7 +30,7 @@ module Rozi
30
30
  end
31
31
 
32
32
  ##
33
- # @returns [Array] the attributes of the track as an Array
33
+ # @return [Array] the attributes of the track as an Array
34
34
  #
35
35
  def attributes
36
36
  [@line_width, @color, @description, @skip_value,
@@ -8,38 +8,29 @@ module Rozi
8
8
  include OziFunctions
9
9
 
10
10
  ##
11
- # Writes the track to +file+ as an Ozi Explorer .plt file.
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
- write_inner = Proc.new { |track, file|
18
- file.write(<<-TEXT)
19
- OziExplorer Track Point File Version 2.1
20
- WGS 84
21
- Altitude is in Feet
22
- Reserved 3
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
- file.write(track.points.count.to_s() + "\n")
25
+ file.write(track_attributes_to_text(track))
26
+ file.write("\n")
29
27
 
30
- track.points.each { |point|
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
- if file.is_a? String
37
- open_file_for_writing(file) { |f|
38
- write_inner.call(track, f)
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)
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rozi
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
@@ -10,10 +10,19 @@ module Rozi
10
10
 
11
11
  include OziFunctions
12
12
 
13
- # TODO: Finish list of symbols.
14
- SYMBOLS = {:default => 3, :house => 10}
15
-
16
- attr_accessor :number, :name, :latitude, :longitude, :date,
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 = 3
29
- @display_format = 4
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, @name, @latitude, @longitude, @date, @symbol, @display_format,
50
- @fg_color, @bg_color, @description, @pointer_direction, @altitude,
51
- @font_size, @font_style, @symbol_size]
52
- end
53
-
54
- def symbol=(value)
55
- if value.is_a? Symbol
56
- value = SYMBOLS[value]
57
- end
58
-
59
- @symbol = value
60
- end
61
-
62
- ##
63
- # Returns the symbol as a +Symbol+ by default. Pass +:number+ to return
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
  ##
@@ -12,27 +12,17 @@ module Rozi
12
12
  include OziFunctions
13
13
 
14
14
  def write(waypoints, file)
15
- write_inner = Proc.new { |waypoints, file|
16
- file.write <<-TEXT
17
- OziExplorer Waypoint File Version 1.1
18
- WGS 84
19
- Reserved 2
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
- if file.is_a? String
30
- file = open_file_for_writing(file) { |f|
31
- write_inner.call(waypoints, f)
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
@@ -1,7 +1,4 @@
1
1
 
2
- require "rozi/track_point"
3
- require "minitest/autorun"
4
-
5
2
  module Rozi
6
3
 
7
4
  class TrackPointTest < Minitest::Test
@@ -1,6 +1,4 @@
1
1
 
2
- require "rozi/track"
3
-
4
2
  module Rozi
5
3
 
6
4
  class TrackTest < Minitest::Test
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "stringio"
3
3
 
4
- require "rozi/track_writer"
5
-
6
4
  module Rozi
7
5
 
8
6
  class TrackWriterTest < Minitest::Test
@@ -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,,3,1,4,0,65535,,0,,,-777,6,0,17",
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: :house)
44
+ wpt = Waypoint.new(name: "test", symbol: 4)
48
45
 
49
46
  assert_equal(
50
- "-1,test,0.000000,0.000000,,10,1,4,0,65535,,0,,,-777,6,0,17",
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,,3,1,4,0,65535,æøåÑ ÆØÅ,0,,,-777,6,0,17",
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.3
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: