Class: Fdc::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/fdc/parser.rb

Overview

Parse record types from IGC file data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



10
11
12
# File 'lib/fdc/parser.rb', line 10

def initialize
  @ready = false
end

Instance Attribute Details

#a_recordObject (readonly)

Returns the value of attribute a_record.



5
6
7
# File 'lib/fdc/parser.rb', line 5

def a_record
  @a_record
end

#b_recordsObject (readonly)

Returns the value of attribute b_records.



7
8
9
# File 'lib/fdc/parser.rb', line 7

def b_records
  @b_records
end

#date_recordObject (readonly)

Returns the value of attribute date_record.



4
5
6
# File 'lib/fdc/parser.rb', line 4

def date_record
  @date_record
end

#h_recordsObject (readonly)

Returns the value of attribute h_records.



6
7
8
# File 'lib/fdc/parser.rb', line 6

def h_records
  @h_records
end

#l_recordsObject (readonly)

Returns the value of attribute l_records.



8
9
10
# File 'lib/fdc/parser.rb', line 8

def l_records
  @l_records
end

Instance Method Details

#parse(igc_file) ⇒ Object

Parse the supplied IGC file content

Parameters:

  • igc_file (String)

    The IGC file content

Raises:



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
# File 'lib/fdc/parser.rb', line 18

def parse(igc_file)
  
  begin
    # parse utc date
    unless @date_record = igc_file.match(REGEX_H_DTE) then
      @ready = false
      raise Fdc::FileFormatError, "Invalid file format - header date is missing"
    end

    # parse a records
    unless @a_record = igc_file.match(REGEX_A) then
      @ready = false
      raise Fdc::FileFormatError, "Invalid file format" unless @a_record
    end

    # parse h records
    @h_records = igc_file.scan(REGEX_H)

    # parse b records
    @b_records = igc_file.scan(REGEX_B)

    # parse l records
    @l_records = igc_file.scan(REGEX_L)
        
  rescue ArgumentError => e
    @ready = false
    raise Fdc::FileFormatError, "Wrong file encoding: #{e.message}"
  end
  
  @ready = true
  
end

#ready?Boolean

Returns true if #parse was successfully called.

Returns:

  • (Boolean)

    true if #parse was successfully called



52
53
54
# File 'lib/fdc/parser.rb', line 52

def ready?
  return @ready
end