Class: AIXM::Executables::Ckmid

Inherits:
Object
  • Object
show all
Defined in:
lib/aixm/executables.rb

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Ckmid

Returns a new instance of Ckmid.


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/aixm/executables.rb', line 45

def initialize(**options)
  OptionParser.new do |o|
    o.banner = <<~END
      Check mid attributes of an OFMX file.
      Usage: #{File.basename($0)} infile.ofmx
    END
    o.on('-A', '--about', 'show author/license information and exit') { AIXM::Executables.about }
    o.on('-V', '--version', 'show version and exit') { AIXM::Executables.version }
  end.parse!
  @infile = ARGV.shift
end

Instance Method Details

#runObject


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/aixm/executables.rb', line 57

def run
  fail 'cannot read file' unless @infile && File.readable?(@infile)
  fail 'file ist not OFMX' unless @infile.match?(/\.ofmx$/)
  AIXM.ofmx!
  document = File.open(@infile) { Nokogiri::XML(_1) }
  errors = Nokogiri::XML::Schema(File.open(AIXM.schema(:xsd))).validate(document)
  errors += AIXM::PayloadHash::Mid.new(document).check_mid
  if errors.any?
    puts errors
    fail "OFMX file has errors"
  end
rescue => error
  puts "ERROR: #{error.message}"
  exit 1
end