class AIPP::LF::ENR54
Obstacles
Constants
- NAME_BLACKLIST
Obstacles to be ignored
- TYPES
Map type descriptions to AIXM types and remarks
Public Instance Methods
parse()
click to toggle source
# File lib/aipp/regions/LF/ENR-5.4.rb 36 def parse 37 tbody = prepare(html: read).css('tbody').last 38 tbody.css('tr').to_enum.with_index(1).each do |tr, index| 39 tds = tr.css('td') 40 name = tds[0].text.cleanup 41 next if NAME_BLACKLIST.include? name 42 elevation, height = tds[4].text.cleanup.split(/[()]/).map { _1.cleanup.remove("\n") } 43 type, type_remarks = TYPES.fetch(tds[2].text.cleanup) 44 count = tds[3].text.cleanup.to_i 45 visibility = tds[5].text.cleanup 46 obstacle = AIXM.obstacle( 47 source: source(position: tr.line), 48 name: name, 49 type: type, 50 xy: xy_from(tds[1].text), 51 z: z_from(elevation + 'AMSL') 52 ).tap do |obstacle| 53 obstacle.height = d_from(height) 54 obstacle.marking = visibility.match?(/jour/i) 55 obstacle.lighting = visibility.match?(/nuit/i) 56 obstacle.remarks = remarks_from(type_remarks, (count if count > 1), tds[6].text) 57 end 58 if count > 1 59 obstacle_group = AIXM.obstacle_group( 60 source: obstacle.source, 61 name: obstacle.name 62 ).tap do |obstacle_group| 63 obstacle_group.remarks = "#{count} obstacles" 64 end 65 obstacle_group.add_obstacle obstacle 66 add obstacle_group 67 else 68 add obstacle 69 end 70 rescue => error 71 warn("error parsing obstacle at ##{index}: #{error.message}", pry: error) 72 end 73 end
Private Instance Methods
remarks_from(*parts)
click to toggle source
# File lib/aipp/regions/LF/ENR-5.4.rb 77 def remarks_from(*parts) 78 part_titles = ['TYPE', 'NUMBER/NOMBRE', 'DETAILS'] 79 [].tap do |remarks| 80 parts.each.with_index do |part, index| 81 if part 82 part = part.to_s.cleanup.blank_to_nil 83 remarks << "**#{part_titles[index]}**\n#{part}" 84 end 85 end 86 end.join("\n\n").blank_to_nil 87 end