rozi 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c63cdef86599183152c63d7c23102fa868709ffb
4
- data.tar.gz: f2990a902a99c2264eb013bc0d046625a924ed51
3
+ metadata.gz: 6351d00ff20f095a7a14131c0e4f44def5067d27
4
+ data.tar.gz: 416b900a4696699ec9247950c36d04bbaf1f7a26
5
5
  SHA512:
6
- metadata.gz: 9cfcc74f0d06872dda67073bd4ca1b3787e88ff9753f45c284781daf386a9c2b80f630c8229e79ea65073ad17356a40db1d54b4061dff5615d9d6497b716ab13
7
- data.tar.gz: c713a377dc8004908d63b8b578c8366751a541039728894f983e6c06665e18472a7da53789619ee8e942c2230921438c9df8e76f447127d9e1db913d4fe2f8de
6
+ metadata.gz: 9cf1116b403989c44d18d5d4fdf899144c374a513047ca6430144ca4a9bb353c2c0386580e8cd3a97d8611fc16ba59ec2b3dddd55344f72966a5f25c06ac283d
7
+ data.tar.gz: 9ff24557115520e3f45728fcf0ab587b034671344a74a5db31275ef4cf6197b9f04dc93bcd6c08f09bb5b12e00d15342951636adb7265c65bacdcf423671d90b
@@ -0,0 +1,130 @@
1
+
2
+ module Rozi
3
+
4
+ ##
5
+ # A list of datums accepted by Ozi Explorer.
6
+ #
7
+ DATUMS = [
8
+ "Adindan",
9
+ "Afgooye",
10
+ "Ain el Abd 1970",
11
+ "Anna 1 Astro 1965",
12
+ "Arc 1950",
13
+ "Arc 1960",
14
+ "Ascension Island 1958",
15
+ "Astro B4 Sorol Atoll",
16
+ "Astro Beacon 1945",
17
+ "Astro DOS 71/4",
18
+ "Astronomic Stn 1952",
19
+ "Australian Geodetic 1966",
20
+ "Australian Geodetic 1984",
21
+ "Australian Geocentric 1994 (GDA94)",
22
+ "Austrian",
23
+ "Bellevue (IGN)",
24
+ "Bermuda 1957",
25
+ "Bogota Observatory",
26
+ "Campo Inchauspe",
27
+ "Canton Astro 1966",
28
+ "Cape",
29
+ "Cape Canaveral",
30
+ "Carthage",
31
+ "CH-1903",
32
+ "Chatham 1971",
33
+ "Chua Astro",
34
+ "Corrego Alegre",
35
+ "Djakarta (Batavia)",
36
+ "DOS 1968",
37
+ "Easter Island 1967",
38
+ "Egypt",
39
+ "European 1950",
40
+ "European 1950 (Mean France)",
41
+ "European 1950 (Spain and Portugal)",
42
+ "European 1979",
43
+ "Finland Hayford",
44
+ "Gandajika Base",
45
+ "Geodetic Datum 1949",
46
+ "Guam 1963",
47
+ "GUX 1 Astro",
48
+ "Hartebeeshoek94",
49
+ "Hermannskogel",
50
+ "Hjorsey 1955",
51
+ "Hong Kong 1963",
52
+ "Hu-Tzu-Shan",
53
+ "Indian Bangladesh",
54
+ "Indian Thailand",
55
+ "Israeli",
56
+ "Ireland 1965",
57
+ "ISTS 073 Astro 1969",
58
+ "Johnston Island",
59
+ "Kandawala",
60
+ "Kerguelen Island",
61
+ "Kertau 1948",
62
+ "L.C. 5 Astro",
63
+ "Liberia 1964",
64
+ "Luzon Mindanao",
65
+ "Luzon Philippines",
66
+ "Mahe 1971",
67
+ "Marco Astro",
68
+ "Massawa",
69
+ "Merchich",
70
+ "Midway Astro 1961",
71
+ "Minna",
72
+ "NAD27 Alaska",
73
+ "NAD27 Bahamas",
74
+ "NAD27 Canada",
75
+ "NAD27 Canal Zone",
76
+ "NAD27 Caribbean",
77
+ "NAD27 Central",
78
+ "NAD27 CONUS",
79
+ "NAD27 Cuba",
80
+ "NAD27 Greenland",
81
+ "NAD27 Mexico",
82
+ "NAD27 San Salvador",
83
+ "NAD83",
84
+ "Nahrwn Masirah Ilnd",
85
+ "Nahrwn Saudi Arbia",
86
+ "Nahrwn United Arab",
87
+ "Naparima BWI",
88
+ "NGO1948",
89
+ "NTF France",
90
+ "Norsk",
91
+ "Observatorio 1966",
92
+ "Old Egyptian",
93
+ "Old Hawaiian",
94
+ "Oman",
95
+ "Ord Srvy Grt Britn",
96
+ "Pico De Las Nieves",
97
+ "Pitcairn Astro 1967",
98
+ "Potsdam Rauenberg DHDN",
99
+ "Prov So Amrican 1956",
100
+ "Prov So Chilean 1963",
101
+ "Puerto Rico",
102
+ "Pulkovo 1942 (1)",
103
+ "Pulkovo 1942 (2)",
104
+ "Qatar National",
105
+ "Qornoq",
106
+ "Reunion",
107
+ "Rijksdriehoeksmeting",
108
+ "Rome 1940",
109
+ "RT 90",
110
+ "S42 ",
111
+ "Santo (DOS)",
112
+ "Sao Braz",
113
+ "Sapper Hill 1943",
114
+ "Schwarzeck",
115
+ "South American 1969",
116
+ "South Asia",
117
+ "Southeast Base",
118
+ "Southwest Base",
119
+ "Timbalai 1948",
120
+ "Tokyo",
121
+ "Tristan Astro 1968",
122
+ "Viti Levu 1916",
123
+ "Wake-Eniwetok 1960",
124
+ "WGS 72",
125
+ "WGS 84",
126
+ "Yacare",
127
+ "Zanderij"
128
+ ]
129
+
130
+ end
@@ -70,4 +70,23 @@ module Rozi
70
70
 
71
71
  return nil
72
72
  end
73
+
74
+ ##
75
+ # Writes a {Rozi::NameSearchText} object to a file.
76
+ #
77
+ # @see Rozi::NameSearchTextWriter#write
78
+ #
79
+ def write_nst(nst, file)
80
+ @@nst_writer ||= NameSearchTextWriter.new
81
+
82
+ if file.is_a? String
83
+ open_file_for_writing(file) { |f|
84
+ @@nst_writer.write(nst, f)
85
+ }
86
+ else
87
+ @@nst_writer.write(nst, file)
88
+ end
89
+
90
+ return nil
91
+ end
73
92
  end
@@ -0,0 +1,23 @@
1
+
2
+ module Rozi
3
+
4
+ ##
5
+ # This class represents a name in an Ozi Explorer name database.
6
+ #
7
+ # @note The +name+, +lat+ and +lng+ fields must be set, or runtime errors will
8
+ # be raised when attempting to write to file.
9
+ #
10
+ class Name
11
+
12
+ attr_accessor :name, :feature_code, :zone, :lat, :lng
13
+
14
+ def initialize(name=nil, feature_code=nil, zone=nil, lat=nil, lng=nil)
15
+ @name = name
16
+ @feature_code = feature_code
17
+ @zone = zone
18
+ @lat = lat
19
+ @lng = lng
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,41 @@
1
+
2
+ module Rozi
3
+
4
+ ##
5
+ # A name search text (.nst) file is a text file that can be converted into a
6
+ # name database used by Ozi Explorer's "name search" functionality. This class
7
+ # represents such a file and can be written to disk using
8
+ # {Rozi::NameSearchTextWriter}.
9
+ #
10
+ class NameSearchText
11
+
12
+ attr_accessor :comment, :datum, :names, :latlng,
13
+ :utm, :utm_zone, :hemisphere
14
+
15
+ include OziFunctions
16
+
17
+ def initialize
18
+ @comment = ""
19
+ @datum = "WGS 84"
20
+ @names = []
21
+
22
+ @latlng = true
23
+ @utm = false
24
+ @utm_zone = nil
25
+ @hemisphere = nil
26
+ end
27
+
28
+ def <<(name)
29
+ @names << name
30
+ end
31
+
32
+ def datum=(datum)
33
+ if not datum_valid?(datum)
34
+ fail ArgumentError, %(Invalid datum: "#{datum}")
35
+ end
36
+
37
+ @datum = datum
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,63 @@
1
+
2
+ module Rozi
3
+
4
+ ##
5
+ # A class for writing {Rozi::NameSearchText} objects to files.
6
+ #
7
+ class NameSearchTextWriter
8
+
9
+ ##
10
+ # Writes +nst+ to +file+.
11
+ #
12
+ # @param [Rozi::NameSearchText] nst
13
+ # @param [File, StringIO] file an open file object
14
+ #
15
+ def write(nst, file)
16
+ if nst.comment
17
+ nst.comment.each_line { |line|
18
+ file.write ";#{line.chomp}\n"
19
+ }
20
+ end
21
+
22
+ file.write construct_first_line(nst) << "\n"
23
+ file.write construct_second_line(nst) << "\n"
24
+
25
+ nst.names.each { |name|
26
+ file.write name_to_line(name) << "\n"
27
+ }
28
+
29
+ return nil
30
+ end
31
+
32
+ private
33
+
34
+ def construct_first_line(nst)
35
+ first_line = "#1,"
36
+
37
+ if nst.utm
38
+ first_line << "UTM,#{nst.utm_zone}"
39
+
40
+ if nst.hemisphere
41
+ first_line << ",#{nst.hemisphere}"
42
+ end
43
+ else
44
+ first_line << ","
45
+ end
46
+
47
+ return first_line
48
+ end
49
+
50
+ def construct_second_line(nst)
51
+ "#2,#{nst.datum}"
52
+ end
53
+
54
+ def name_to_line(name)
55
+ if not name.name or not name.lat or not name.lng
56
+ raise "name, lat and lng must be set!"
57
+ end
58
+
59
+ "#{name.name},#{name.feature_code},#{name.zone},#{name.lat},#{name.lng}"
60
+ end
61
+ end
62
+
63
+ end
@@ -22,8 +22,8 @@ module Rozi
22
22
  # @return [Integer]
23
23
  #
24
24
  # @example
25
- # interpret_color(255) # 255
26
- # interpret_color("ABCDEF") # 15715755
25
+ # interpret_color(255) # => 255
26
+ # interpret_color("ABCDEF") # => 15715755
27
27
  #
28
28
  def interpret_color(color)
29
29
  if color.is_a? String
@@ -34,6 +34,15 @@ module Rozi
34
34
 
35
35
  color
36
36
  end
37
+
38
+ ##
39
+ # Checks if +datum+ is a valid datum according to Ozi Explorer.
40
+ #
41
+ # @return [Boolean] true if +datum+ is valid
42
+ #
43
+ def datum_valid?(datum)
44
+ Rozi::DATUMS.include? datum
45
+ end
37
46
  end
38
47
 
39
48
  end
@@ -8,7 +8,8 @@ module Rozi
8
8
  class Track
9
9
  attr_accessor :points
10
10
 
11
- attr_accessor :line_width, :color, :description, :skip_value, :type,
11
+ attr_reader :color
12
+ attr_accessor :line_width, :description, :skip_value, :type,
12
13
  :fill_type, :fill_color
13
14
 
14
15
  DEFAULTS = {
@@ -21,6 +22,8 @@ module Rozi
21
22
  fill_color: 0
22
23
  }
23
24
 
25
+ include OziFunctions
26
+
24
27
  def initialize(args={})
25
28
  @points = args[:points] || []
26
29
 
@@ -29,6 +32,10 @@ module Rozi
29
32
  args.each_pair { |key, value| set(key, value) }
30
33
  end
31
34
 
35
+ def color=(color)
36
+ @color = interpret_color(color)
37
+ end
38
+
32
39
  ##
33
40
  # @return [Array] the attributes of the track as an Array
34
41
  #
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rozi
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
@@ -0,0 +1,28 @@
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
@@ -0,0 +1,114 @@
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
@@ -0,0 +1,33 @@
1
+
2
+ module Rozi
3
+
4
+ class OziFunctionsTest < Minitest::Test
5
+ def setup
6
+ @subject = Class.new {
7
+ include OziFunctions
8
+ }.new
9
+ end
10
+
11
+ def test_escape_text
12
+ assert_equal "FooÑ barÑ baz", @subject.escape_text("Foo, bar, baz")
13
+ end
14
+
15
+ def test_interpret_color_integer
16
+ assert_equal 255, @subject.interpret_color(255)
17
+ end
18
+
19
+ def test_interpret_color_hash
20
+ assert_equal 15715755, @subject.interpret_color("ABCDEF")
21
+ end
22
+
23
+ def test_datum_valid?
24
+ assert @subject.datum_valid?("WGS 84")
25
+ assert @subject.datum_valid?("Norsk")
26
+ assert @subject.datum_valid?("Egypt")
27
+
28
+ refute @subject.datum_valid?("Coolywobbles")
29
+ refute @subject.datum_valid?("Rambunctious")
30
+ end
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -1,25 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rozi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Sandven
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: |2
14
- Contains classes for creating Waypoint files and Track files for Ozi
15
- Explorer.
13
+ description: A gem for working with several Ozi Explorer file formats
16
14
  email: tomas191191@gmail.com
17
15
  executables: []
18
16
  extensions: []
19
17
  extra_rdoc_files: []
20
18
  files:
21
19
  - lib/rozi.rb
20
+ - lib/rozi/datums.rb
22
21
  - lib/rozi/module_functions.rb
22
+ - lib/rozi/name.rb
23
+ - lib/rozi/name_search_text.rb
24
+ - lib/rozi/name_search_text_writer.rb
23
25
  - lib/rozi/ozi_functions.rb
24
26
  - lib/rozi/track.rb
25
27
  - lib/rozi/track_point.rb
@@ -28,6 +30,9 @@ files:
28
30
  - lib/rozi/waypoint.rb
29
31
  - lib/rozi/waypoint_writer.rb
30
32
  - test/rozi/module_functions_test.rb
33
+ - test/rozi/name_search_text_test.rb
34
+ - test/rozi/name_search_text_writer_test.rb
35
+ - test/rozi/ozi_functions_test.rb
31
36
  - test/rozi/track_point_test.rb
32
37
  - test/rozi/track_test.rb
33
38
  - test/rozi/track_writer_test.rb
@@ -58,10 +63,13 @@ signing_key:
58
63
  specification_version: 4
59
64
  summary: A gem for working with several Ozi Explorer file formats
60
65
  test_files:
61
- - test/rozi/waypoint_test.rb
62
- - test/rozi/track_point_test.rb
63
66
  - test/rozi/track_writer_test.rb
64
- - test/rozi/waypoint_writer_test.rb
65
67
  - test/rozi/track_test.rb
66
68
  - test/rozi/module_functions_test.rb
69
+ - test/rozi/ozi_functions_test.rb
70
+ - test/rozi/waypoint_test.rb
71
+ - test/rozi/name_search_text_writer_test.rb
72
+ - test/rozi/track_point_test.rb
73
+ - test/rozi/name_search_text_test.rb
74
+ - test/rozi/waypoint_writer_test.rb
67
75
  has_rdoc: