lib/bolognese/schema_org.rb in bolognese-0.8.13 vs lib/bolognese/schema_org.rb in bolognese-0.9
- old
+ new
@@ -15,25 +15,30 @@
if string.present?
@raw = string
elsif id.present?
response = Maremma.get(id)
- doc = Nokogiri::XML(response.body.fetch("data", nil))
+ doc = Nokogiri::XML(response.body.fetch("data", nil), nil, 'UTF-8')
@raw = doc.at_xpath('//script[@type="application/ld+json"]')
+ @raw = @raw.text if @raw.present?
end
end
def metadata
- @metadata ||= raw.present? ? Maremma.from_json(raw) : {}
+ @metadata ||= raw.present? && valid? ? Maremma.from_json(raw) : {}
end
def exists?
metadata.present?
end
+ def errors
+ jsonlint(raw)
+ end
+
def valid?
- schema_org.present?
+ errors.empty?
end
def doi
validate_doi(id)
end
@@ -59,10 +64,10 @@
end
def ris_type
SO_TO_RIS_TRANSLATIONS[resource_type_general.to_s.dasherize] || "GEN"
end
-
+
def additional_type
metadata.fetch("additionalType", nil)
end
def bibtex_type