class Relaton::Bibdata
Constants
- DOC_NUMBER_REGEX
- FILENAME_BAD_CHARS
From gavinmiller.io/2016/creating-a-secure-sanitization-function/
- URL_TYPES
Attributes
bibitem[R]
@return [RelatonBib::BibliographicItem]
Public Class Methods
from_xml(source)
click to toggle source
# File lib/relaton/bibdata.rb, line 40 def self.from_xml(source) bi = Relaton::Cli.parse_xml(source) new(bi) if bi end
new(bibitem)
click to toggle source
@param bibitem [RelatonBib::BibliographicItem]
# File lib/relaton/bibdata.rb, line 11 def initialize(bibitem) @bibitem = bibitem end
Public Instance Methods
doc_number()
click to toggle source
# File lib/relaton/bibdata.rb, line 36 def doc_number docidentifier&.match(DOC_NUMBER_REGEX) ? $2.to_i : 999999 end
docidentifier()
click to toggle source
# File lib/relaton/bibdata.rb, line 15 def docidentifier @bibitem.docidentifier.first&.id end
docidentifier_code()
click to toggle source
# File lib/relaton/bibdata.rb, line 27 def docidentifier_code return "" if docidentifier.nil? FILENAME_BAD_CHARS.reduce(docidentifier.downcase) do |result, bad_char| result.gsub(bad_char, "-") end end
method_missing(meth, *args)
click to toggle source
rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Style/MissingRespondToMissing
Calls superclass method
# File lib/relaton/bibdata.rb, line 67 def method_missing(meth, *args) if @bibitem.respond_to?(meth) @bibitem.send meth, *args elsif URL_TYPES.include? meth link = @bibitem.link.detect do |l| l.type == meth.to_s || meth == :uri && l.type.nil? end link&.content&.to_s elsif URL_TYPES.include? meth.match(/^\w+(?==)/).to_s.to_sym /^(?<type>\w+)/ =~ meth link = @bibitem.link.detect do |l| l.type == type || type == "uri" && l.type.nil? end if link link.content = args[0] else @bibitem.link << RelatonBib::TypedUri.new(type: type, content: args[0]) end else super end end
to_h()
click to toggle source
# File lib/relaton/bibdata.rb, line 52 def to_h URL_TYPES.reduce(@bibitem.to_hash) do |h, t| value = send t h[t.to_s] = value h end end
to_xml(opts = {})
click to toggle source
# File lib/relaton/bibdata.rb, line 45 def to_xml(opts = {}) options = { bibdata: true, date_format: :full }.merge( opts.select { |k, _v| k.is_a? Symbol } ) @bibitem.to_xml **options end
to_yaml()
click to toggle source
# File lib/relaton/bibdata.rb, line 60 def to_yaml to_h.to_yaml end