lib/aipp/parser.rb in aipp-0.2.5 vs lib/aipp/parser.rb in aipp-0.2.6
- old
+ new
@@ -26,16 +26,17 @@
def initialize(options:)
@options = options
@options[:storage] = options[:storage].join(options[:region])
@options[:storage].mkpath
@config = {}
- @aixm = AIXM.document(region: @options[:region], effective_at: @options[:airac].date)
+ @aixm = AIXM.document(effective_at: @options[:airac].date)
@dependencies = THash.new
@fixtures = {}
@borders = {}
@cache = OpenStruct.new
AIXM.send("#{options[:schema]}!")
+ AIXM.config.region = options[:region]
end
# Read the configuration from config.yml.
def read_config
info("Reading config.yml")
@@ -87,70 +88,84 @@
fixture: @fixtures[aip],
parser: self
).attach_patches.tap(&:parse).detach_patches
end
end
+ if options[:grouped_obstacles]
+ info("Grouping obstacles")
+ aixm.group_obstacles!
+ end
+ info("Counting #{aixm.features.count} features")
end
# Validate the AIXM document.
#
# @raise [RuntimeError] if the document is not valid
def validate_aixm
+ info("Detecting duplicates")
+ if (duplicates = aixm.features.duplicates).any?
+ message = "duplicates found:\n" + duplicates.map { "#{_1.inspect} from #{_1.source}" }.join("\n")
+ @options[:force] ? warn(message, pry: binding) : fail(message)
+ end
info("Validating #{options[:schema].upcase}")
unless aixm.valid?
message = "invalid #{options[:schema].upcase} document:\n" + aixm.errors.map(&:message).join("\n")
@options[:force] ? warn(message, pry: binding) : fail(message)
end
end
- # Write the AIXM document.
- def write_aixm
- info("Writing #{aixm_file}")
- AIXM.config.mid_region = options[:region] if options[:mid]
- File.write(aixm_file, aixm.to_xml)
- end
-
# Write the AIXM document and context information.
def write_build
- info("Writing build")
- builds_path.mkpath
- build_file = builds_path.join("#{@options[:airac].date.xmlschema}.zip")
- build_file.delete if build_file.exist?
- Dir.mktmpdir do |tmp_dir|
- tmp_dir = Pathname(tmp_dir)
- AIXM.config.mid_region = options[:region]
- # AIXM/OFMX file
- File.write(tmp_dir.join(aixm_file), aixm.to_xml)
- # Build details
- File.write(
- tmp_dir.join('build.yaml'), {
- version: AIPP::VERSION,
- config: @config,
- options: @options
- }.to_yaml
- )
- # Manifest
- manifest, buffer, feature, uid, comment = [], '', '', '', ''
- File.open(tmp_dir.join(aixm_file)).each do |line|
- buffer << line
- case line
- when /^ {2}<(\w{3}) / then buffer, feature = line, $1
- when /^ {4}<#{feature}Uid mid="(.*?)"/ then uid = $1
- when /^ {2}<!-- (.*) -->/ then comment = $1
- when /^ {2}<\/#{feature}>/
- manifest << [feature, uid[0,8], buffer.payload_hash(region: options[:region])[0,8], comment].to_csv
- feature, uid = '', ''
+ if @options[:aip]
+ info ("Skipping build")
+ else
+ info("Writing build")
+ builds_path.mkpath
+ build_file = builds_path.join("#{@options[:airac].date.xmlschema}.zip")
+ Dir.mktmpdir do |tmp_dir|
+ tmp_dir = Pathname(tmp_dir)
+ # AIXM/OFMX file
+ AIXM.config.mid = true
+ File.write(tmp_dir.join(aixm_file), aixm.to_xml)
+ # Build details
+ File.write(
+ tmp_dir.join('build.yaml'), {
+ version: AIPP::VERSION,
+ config: @config,
+ options: @options
+ }.to_yaml
+ )
+ # Manifest
+ manifest, buffer, feature, aip, uid, comment = [], '', '', '', '', ''
+ File.open(tmp_dir.join(aixm_file)).each do |line|
+ buffer << line
+ case line
+ when /^ {2}<(\w{3}).*source=".*?\|.*?\|(.*?)\|/ then buffer, feature, aip = line, $1, $2
+ when /^ {4}<#{feature}Uid[^>]+?mid="(.*?)"/ then uid = $1
+ when /^ {2}<!-- (.*) -->/ then comment = $1
+ when /^ {2}<\/#{feature}>/
+ manifest << [aip, feature, uid[0,8], AIXM::PayloadHash.new(buffer).to_uuid[0,8], comment].to_csv
+ feature, aip, uid = '', '', ''
+ end
end
- end
- manifest = manifest.sort.prepend "Feature,Short Uid Hash,Short Feature Hash,Comment\n"
- File.write(tmp_dir.join('manifest.csv'), manifest.join)
- # Zip it
- Zip::File.open(build_file, Zip::File::CREATE) do |zip|
- tmp_dir.children.each do |entry|
- zip.add(entry.basename.to_s, entry) unless entry.basename.to_s[0] == '.'
+ manifest = manifest.sort.prepend "AIP,Feature,Short Uid Hash,Short Feature Hash,Comment\n"
+ File.write(tmp_dir.join('manifest.csv'), manifest.join)
+ # Zip it
+ build_file.delete if build_file.exist?
+ Zip::File.open(build_file, Zip::File::CREATE) do |zip|
+ tmp_dir.children.each do |entry|
+ zip.add(entry.basename.to_s, entry) unless entry.basename.to_s[0] == '.'
+ end
end
end
end
+ end
+
+ # Write the AIXM document.
+ def write_aixm
+ info("Writing #{aixm_file}")
+ AIXM.config.mid = options[:mid]
+ File.write(aixm_file, aixm.to_xml)
end
# Write the configuration to config.yml.
def write_config
info("Writing config.yml")