Class: Fdc::Parser
- Inherits:
-
Object
- Object
- Fdc::Parser
- Defined in:
- lib/fdc/parser.rb
Overview
Parse record types from IGC file data
Instance Attribute Summary collapse
-
#a_record ⇒ Object
readonly
Returns the value of attribute a_record.
-
#b_records ⇒ Object
readonly
Returns the value of attribute b_records.
-
#date_record ⇒ Object
readonly
Returns the value of attribute date_record.
-
#h_records ⇒ Object
readonly
Returns the value of attribute h_records.
-
#l_records ⇒ Object
readonly
Returns the value of attribute l_records.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
-
#parse(igc_file) ⇒ Object
Parse the supplied IGC file content.
-
#ready? ⇒ Boolean
True if #parse was successfully called.
Constructor Details
#initialize ⇒ Parser
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_record ⇒ Object (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_records ⇒ Object (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_record ⇒ Object (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_records ⇒ Object (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_records ⇒ Object (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
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.}" end @ready = true end |
#ready? ⇒ Boolean
Returns true if #parse was successfully called.
52 53 54 |
# File 'lib/fdc/parser.rb', line 52 def ready? return @ready end |