class OJXV::JatsFile
VALIDATING JATS against DTD DTD schemas from jats.nlm.nih.gov/archiving/1.3/dtd.html
Attributes
errors[RW]
filepath[R]
Public Class Methods
new(path)
click to toggle source
# File lib/ojxv/jats_file.rb, line 13 def initialize(path) @errors = nil raise ::OJXV::FileNotFound, "Can't find file: #{path}" unless File.exist?(path) @filepath = path end
supported_schema_versions()
click to toggle source
# File lib/ojxv/jats_file.rb, line 43 def self.supported_schema_versions ["1.1", "1.1d1", "1.1d2", "1.1d3", "1.2", "1.2d1", "1.2d2", "1.3d1", "1.3"] end
Public Instance Methods
valid_jats?(schema_version="1.3")
click to toggle source
# File lib/ojxv/jats_file.rb, line 19 def valid_jats?(schema_version="1.3") @errors = nil FileUtils.mkdir_p(local_path) FileUtils.cp_r schema_files_path(schema_version), local_path FileUtils.cp @filepath, local_path new_filepath = File.join(local_path, File.basename(@filepath)) doc = Nokogiri::XML(File.open(new_filepath)) do |config| config.dtdload.dtdvalid end raise(NoDTD, "File has no DTD declaration") if doc.external_subset.nil? @errors = doc.external_subset.validate(doc) @errors.empty? rescue Nokogiri::XML::SyntaxError => e raise ::OJXV::XMLParsingError, e.message ensure cleanup end
Private Instance Methods
cleanup()
click to toggle source
# File lib/ojxv/jats_file.rb, line 61 def cleanup FileUtils.rm_rf(local_path) if Dir.exist?(local_path) end
local_path()
click to toggle source
# File lib/ojxv/jats_file.rb, line 57 def local_path @local_path ||= "tmp-ojxv-jats-#{SecureRandom.hex(3)}" end
schema_files_path(schema_version)
click to toggle source
# File lib/ojxv/jats_file.rb, line 49 def schema_files_path(schema_version) unless JatsFile.supported_schema_versions.include?(schema_version) raise ::OJXV::UnsupportedJATSSchemaVersion, "Unsupported JATS schema version: #{schema_version}" end File.join(File.dirname(__FILE__), "schemas", "jats", schema_version.to_s, ".") end