Class: OJXV::CrossrefMetadataFile
- Inherits:
-
Object
- Object
- OJXV::CrossrefMetadataFile
- Defined in:
- lib/ojxv/crossref_metadata_file.rb
Overview
VALIDATING CROSSREF against the XSD Crossref bundle v0.3.1 from gitlab.com/crossref/schema/-/releases
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#file ⇒ Object
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filepath) ⇒ CrossrefMetadataFile
constructor
A new instance of CrossrefMetadataFile.
- #valid_crossref?(crossref_version = "5.3.1") ⇒ Boolean
Constructor Details
#initialize(filepath) ⇒ CrossrefMetadataFile
Returns a new instance of CrossrefMetadataFile.
11 12 13 14 15 16 17 18 |
# File 'lib/ojxv/crossref_metadata_file.rb', line 11 def initialize(filepath) @errors = nil if File.exist?(filepath) @file = File.open(filepath) else raise ::OJXV::FileNotFound, "Can't find file: #{filepath}" end end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'lib/ojxv/crossref_metadata_file.rb', line 8 def errors @errors end |
#file ⇒ Object
Returns the value of attribute file.
9 10 11 |
# File 'lib/ojxv/crossref_metadata_file.rb', line 9 def file @file end |
Class Method Details
.supported_schema_versions ⇒ Object
33 34 35 |
# File 'lib/ojxv/crossref_metadata_file.rb', line 33 def self.supported_schema_versions ["4.8.0", "4.8.1", "5.1.0", "5.2.0", "5.3.0", "5.3.1"] end |
Instance Method Details
#valid_crossref?(crossref_version = "5.3.1") ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ojxv/crossref_metadata_file.rb', line 20 def valid_crossref?(crossref_version="5.3.1") @errors = nil xsd = Nokogiri::XML::Schema(schema(crossref_version)) doc = Nokogiri::XML(file.read) @errors = xsd.validate(doc) @errors.empty? rescue Nokogiri::XML::SyntaxError => e raise ::OJXV::XMLParsingError, e. end |