Class: Fdc::Converter
- Inherits:
-
Object
- Object
- Fdc::Converter
- Includes:
- FileLoader, FileWriter
- Defined in:
- lib/fdc/converter.rb
Overview
Convert IGC Files to KML
Instance Attribute Summary collapse
-
#kml ⇒ String
readonly
Get the compiled KML document.
Attributes included from FileLoader
Instance Method Summary collapse
-
#compile(clamp = false, extrude = false, gps = false) ⇒ Object
Compile the KML document from the parsed IGC file.
-
#export(dir = nil) ⇒ Object
Export the compiled KML document.
-
#initialize ⇒ Converter
constructor
A new instance of Converter.
-
#parse(file, encoding = "ISO-8859-1") ⇒ Object
Load and parse an IGC file from the supplied path.
Constructor Details
Instance Attribute Details
#kml ⇒ String (readonly)
Get the compiled KML document
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fdc/converter.rb', line 18 class Fdc::Converter # Mixins include Fdc::FileLoader include Fdc::FileWriter def initialize @parser = Fdc::Parser.new @compiler = Fdc::Compiler.new @parser end # Load and parse an IGC file from the supplied path. # # @param [String] file The path to the IGC file # @param [String] encoding The encoding of the input file # @raise [Fdc::FileReadError] If file could not be loaded # @raise [Fdc::FileFormatError] If the file format is invalid def parse(file, encoding="ISO-8859-1") path = Pathname.new(file) load(path, encoding) @parser.parse @file end # Compile the KML document from the parsed IGC file. # # @param [Boolean] clamp Whether the track should be clamped to the ground # @param [Boolean] extrude Whether the track should be extruded to the ground # @param [Boolean] gps Whether GPS altitude information should be used # @raise [RuntimeError] If {#parse} was not called before def compile(clamp=false, extrude=false, gps=false) # State assertion raise RuntimeError, "Cannot compile without preceding parse" unless @parser.ready? name = @path.basename(@path.extname) @compiler.compile name, clamp, extrude, gps end # Export the compiled KML document # # @param [String] dir The alternative output directory. # If nothing is supplied the files are written to the same location # as the IGC input file. # @raise [RuntimeError] If {#parse} and {#compile} were not called before # @raise [Fdc::FileWriteError] If dirname is not a directory or write protected def export(dir = nil) # Assert state raise RuntimeError, "Cannot export before compile was called" unless @compiler.kml dir = @path.dirname.to_s unless dir write Pathname.new(dir) + (@path.basename(@path.extname).to_s << ".kml"), @compiler.kml end # Get the compiled KML document # @return [String] The compiled KML document def kml @compiler.kml end end |
Instance Method Details
#compile(clamp = false, extrude = false, gps = false) ⇒ Object
Compile the KML document from the parsed IGC file.
49 50 51 52 53 54 55 56 57 |
# File 'lib/fdc/converter.rb', line 49 def compile(clamp=false, extrude=false, gps=false) # State assertion raise RuntimeError, "Cannot compile without preceding parse" unless @parser.ready? name = @path.basename(@path.extname) @compiler.compile name, clamp, extrude, gps end |
#export(dir = nil) ⇒ Object
Export the compiled KML document
66 67 68 69 70 71 72 73 74 |
# File 'lib/fdc/converter.rb', line 66 def export(dir = nil) # Assert state raise RuntimeError, "Cannot export before compile was called" unless @compiler.kml dir = @path.dirname.to_s unless dir write Pathname.new(dir) + (@path.basename(@path.extname).to_s << ".kml"), @compiler.kml end |
#parse(file, encoding = "ISO-8859-1") ⇒ Object
Load and parse an IGC file from the supplied path.
35 36 37 38 39 40 41 |
# File 'lib/fdc/converter.rb', line 35 def parse(file, encoding="ISO-8859-1") path = Pathname.new(file) load(path, encoding) @parser.parse @file end |