Class: AIXM::Executables::Mkmid
Instance Method Summary collapse
-
#initialize(**options) ⇒ Mkmid
constructor
A new instance of Mkmid.
- #run ⇒ Object
Constructor Details
#initialize(**options) ⇒ Mkmid
Returns a new instance of Mkmid.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/aixm/executables.rb', line 7 def initialize(**) = OptionParser.new do |o| o. = " Add mid attributes to OFMX files.\n Usage: \#{File.basename($0)} files\n END\n o.on('-i', '--[no-]in-place', 'overwrite file instead of dumping to STDOUT (default: false)') { @options[:in_place] = _1 }\n o.on('-f', '--[no-]force', 'ignore XML schema validation errors (default: false)') { @options[:force] = _1 }\n o.on('-A', '--about', 'show author/license information and exit') { AIXM::Executables.about }\n o.on('-V', '--version', 'show version and exit') { AIXM::Executables.version }\n end.parse!\n @files = ARGV\nend\n" |
Instance Method Details
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aixm/executables.rb', line 22 def run @files.each do |file| fail "cannot read #{file}" unless file && File.readable?(file) fail "#{file} is not OFMX" unless file.match?(/\.ofmx$/) AIXM.ofmx! document = File.open(file) { Nokogiri::XML(_1) } AIXM::PayloadHash::Mid.new(document).insert_mid errors = Nokogiri::XML::Schema(File.open(AIXM.schema(:xsd))).validate(document) case when errors.any? && ![:force] fail (["#{file} is not valid..."] + errors).join("\n") when [:in_place] File.write(file, document.to_xml) else puts document.to_xml end rescue => error puts "ERROR: #{error.message}" exit 1 end end |