Module: Rozi

Extended by:
Rozi
Included in:
Rozi
Defined in:
lib/rozi.rb,
lib/rozi/datums.rb,
lib/rozi/shared.rb,
lib/rozi/tracks.rb,
lib/rozi/version.rb,
lib/rozi/waypoints.rb,
lib/rozi/name_search.rb,
lib/rozi/module_functions.rb,
lib/rozi/file_wrapper_base.rb

Defined Under Namespace

Modules: Shared Classes: FileWrapperBase, Name, NameSearchProperties, NameSearchTextFile, TrackFile, TrackPoint, TrackProperties, Waypoint, WaypointFile, WaypointFileProperties

Constant Summary collapse

ROOT =
File.expand_path("../", File.dirname(__FILE__))
DATUMS =

A list of datums accepted by Ozi Explorer.

[
  "Adindan",
  "Afgooye",
  "Ain el Abd 1970",
  "Anna 1 Astro 1965",
  "Arc 1950",
  "Arc 1960",
  "Ascension Island 1958",
  "Astro B4 Sorol Atoll",
  "Astro Beacon 1945",
  "Astro DOS 71/4",
  "Astronomic Stn 1952",
  "Australian Geodetic 1966",
  "Australian Geodetic 1984",
  "Australian Geocentric 1994 (GDA94)",
  "Austrian",
  "Bellevue (IGN)",
  "Bermuda 1957",
  "Bogota Observatory",
  "Campo Inchauspe",
  "Canton Astro 1966",
  "Cape",
  "Cape Canaveral",
  "Carthage",
  "CH-1903",
  "Chatham 1971",
  "Chua Astro",
  "Corrego Alegre",
  "Djakarta (Batavia)",
  "DOS 1968",
  "Easter Island 1967",
  "Egypt",
  "European 1950",
  "European 1950 (Mean France)",
  "European 1950 (Spain and Portugal)",
  "European 1979",
  "Finland Hayford",
  "Gandajika Base",
  "Geodetic Datum 1949",
  "Guam 1963",
  "GUX 1 Astro",
  "Hartebeeshoek94",
  "Hermannskogel",
  "Hjorsey 1955",
  "Hong Kong 1963",
  "Hu-Tzu-Shan",
  "Indian Bangladesh",
  "Indian Thailand",
  "Israeli",
  "Ireland 1965",
  "ISTS 073 Astro 1969",
  "Johnston Island",
  "Kandawala",
  "Kerguelen Island",
  "Kertau 1948",
  "L.C. 5 Astro",
  "Liberia 1964",
  "Luzon Mindanao",
  "Luzon Philippines",
  "Mahe 1971",
  "Marco Astro",
  "Massawa",
  "Merchich",
  "Midway Astro 1961",
  "Minna",
  "NAD27 Alaska",
  "NAD27 Bahamas",
  "NAD27 Canada",
  "NAD27 Canal Zone",
  "NAD27 Caribbean",
  "NAD27 Central",
  "NAD27 CONUS",
  "NAD27 Cuba",
  "NAD27 Greenland",
  "NAD27 Mexico",
  "NAD27 San Salvador",
  "NAD83",
  "Nahrwn Masirah Ilnd",
  "Nahrwn Saudi Arbia",
  "Nahrwn United Arab",
  "Naparima BWI",
  "NGO1948",
  "NTF France",
  "Norsk",
  "Observatorio 1966",
  "Old Egyptian",
  "Old Hawaiian",
  "Oman",
  "Ord Srvy Grt Britn",
  "Pico De Las Nieves",
  "Pitcairn Astro 1967",
  "Potsdam Rauenberg DHDN",
  "Prov So Amrican 1956",
  "Prov So Chilean 1963",
  "Puerto Rico",
  "Pulkovo 1942 (1)",
  "Pulkovo 1942 (2)",
  "Qatar National",
  "Qornoq",
  "Reunion",
  "Rijksdriehoeksmeting",
  "Rome 1940",
  "RT 90",
  "S42       ",
  "Santo (DOS)",
  "Sao Braz",
  "Sapper Hill 1943",
  "Schwarzeck",
  "South American 1969",
  "South Asia",
  "Southeast Base",
  "Southwest Base",
  "Timbalai 1948",
  "Tokyo",
  "Tristan Astro 1968",
  "Viti Levu 1916",
  "Wake-Eniwetok 1960",
  "WGS 72",
  "WGS 84",
  "Yacare",
  "Zanderij"
]
VERSION =
"0.1.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.open_file(path, mode = "r") ⇒ File .open_file(path, mode = "r") {|file| ... } ⇒ void

Opens a file with the correct settings for usage with Ozi Explorer

The file instance has UTF-8 internal encoding and ISO-8859-1 external encoding. When writing, all line endings are converted to CRLF. When reading, all line endings are converted to LF.

Overloads:

  • .open_file(path, mode = "r") ⇒ File

    Parameters:

    • path (String)

    Returns:

    • (File)
  • .open_file(path, mode = "r") {|file| ... } ⇒ void

    This method returns an undefined value.

    Can be called with a block, just like file File.open.

    Yield Parameters:

    • file (File)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rozi/module_functions.rb', line 24

def open_file(path, mode="r")
  file = File.open(path, mode)
  opts = {undef: :replace, replace: "?"}

  if mode.include? "w"
    opts[:crlf_newline] = true
  else
    opts[:universal_newline] = true
  end

  file.set_encoding("ISO-8859-1", "UTF-8", opts)

  if block_given?
    yield file
    file.close

    return nil
  else
    return file
  end
end

.write_waypoints(waypoints, file_path, **properties) ⇒ Object

Writes an enumerable of waypoints to a file

Parameters:

  • waypoints (Enumerable)
  • file_path (String)
  • properties (Hash)

    Any extra keyword arguments are processed as waypoint file properties



14
15
16
17
18
19
20
21
22
23
# File 'lib/rozi/waypoints.rb', line 14

def self.write_waypoints(waypoints, file_path, **properties)
  wpt_file = WaypointFile.open(file_path, "w")

  wpt_file.write_properties(WaypointFileProperties.new(**properties))
  wpt_file.write waypoints

  wpt_file.close

  nil
end

Instance Method Details

#require_libObject

Loads all ruby files under lib/rozi. Called automatically when requiring “rozi.rb”.



13
14
15
16
17
18
19
20
# File 'lib/rozi.rb', line 13

def require_lib
  this_dir = File.absolute_path(File.dirname(__FILE__))
  source_files = Dir[File.join(this_dir, "rozi/**/*.rb")]

  source_files.each { |file|
    require_relative file
  }
end

#write_nst(enumerable, file_path, **properties) ⇒ Object

Writes an enumerable of names to a file

All keyword arguments are used as track properties.

Parameters:

  • enumerable (Enumerable)
  • file_path (String)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rozi/name_search.rb', line 14

def write_nst(enumerable, file_path, **properties)
  NameSearchTextFile.open(file_path, "w") { |nst|
    nst.write_properties NameSearchProperties.new(**properties)

    enumerable.each { |name|
      nst.write_name name
    }
  }

  return nil
end

#write_track(enumerable, file_path, **properties) ⇒ Object

Writes an enumerable of track points to a file

All keyword arguments are used as track properties.

Parameters:

  • enumerable (Enumerable)
  • file_path (String)


14
15
16
17
18
19
# File 'lib/rozi/tracks.rb', line 14

def write_track(enumerable, file_path, **properties)
  TrackFile.open(file_path, "w") { |track_file|
    track_file.write_track_properties TrackProperties.new(**properties)
    track_file.write enumerable
  }
end