Class: Relaton::Db
- Inherits:
-
Object
- Object
- Relaton::Db
- Defined in:
- lib/relaton/db.rb
Instance Method Summary collapse
-
#combine_doc(code, year, opts, stdclass) ⇒ nil, ...
RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem, RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem, RelatonW3c::W3cBibliographicItem.
-
#docid_type(code) ⇒ Array
The document identifier class corresponding to the given code.
-
#fetch(code, year = nil, opts = {}) ⇒ nil, ...
The class of reference requested is determined by the prefix of the code: GB Standard for gbbib, IETF for ietfbib, ISO for isobib, IEC or IEV for iecbib,.
-
#fetch_std(code, year = nil, stdclass = nil, opts = {}) ⇒ nil, ...
RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem, RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem, RelatonW3c::W3cBibliographicItem.
-
#initialize(global_cache, local_cache) ⇒ Db
constructor
A new instance of Db.
- #load_entry(key) ⇒ Hash
- #save_entry(key, value) ⇒ Object
-
#to_xml ⇒ String
list all entries as a serialization.
Constructor Details
#initialize(global_cache, local_cache) ⇒ Db
Returns a new instance of Db.
11 12 13 14 15 16 17 18 19 |
# File 'lib/relaton/db.rb', line 11 def initialize(global_cache, local_cache) @registry = Relaton::Registry.instance @db = open_cache_biblio(global_cache, type: :global) @local_db = open_cache_biblio(local_cache, type: :local) @db_name = global_cache @local_db_name = local_cache static_db_name = File. "../relaton/static_cache", __dir__ @static_db = open_cache_biblio static_db_name end |
Instance Method Details
#combine_doc(code, year, opts, stdclass) ⇒ nil, ...
Returns RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem, RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem, RelatonW3c::W3cBibliographicItem.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/relaton/db.rb', line 56 def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength if (refs = code.split " + ").size > 1 reltype = "derivedFrom" reldesc = nil elsif (refs = code.split ", ").size > 1 reltype = "complements" reldesc = RelatonBib::FormattedString.new content: "amendment" else return end doc = @registry.processors[stdclass].hash_to_bib docid: { id: code } ref = refs[0] updates = check_bibliocache(ref, year, opts, stdclass) doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates, type: "updates") if updates refs[1..-1].each_with_object(doc) do |c, d| bib = check_bibliocache("#{ref}/#{c}", year, opts, stdclass) if bib d.relation << RelatonBib::DocumentRelation.new(type: reltype, description: reldesc, bibitem: bib) end end end |
#docid_type(code) ⇒ Array
The document identifier class corresponding to the given code
103 104 105 106 107 |
# File 'lib/relaton/db.rb', line 103 def docid_type(code) stdclass = standard_class(code) or return [nil, code] _prefix, code = strip_id_wrapper(code, stdclass) [@registry.processors[stdclass].idtype, code] end |
#fetch(code, year = nil, opts = {}) ⇒ nil, ...
The class of reference requested is determined by the prefix of the code: GB Standard for gbbib, IETF for ietfbib, ISO for isobib, IEC or IEV for iecbib,
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/relaton/db.rb', line 34 def fetch(code, year = nil, opts = {}) stdclass = standard_class(code) || return processor = @registry.processors[stdclass] ref = processor.respond_to?(:urn_to_code) ? processor.urn_to_code(code)&.first : code ref ||= code cd = combine_doc ref, year, opts, stdclass return cd if cd check_bibliocache(ref, year, opts, stdclass) end |
#fetch_std(code, year = nil, stdclass = nil, opts = {}) ⇒ nil, ...
Returns RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem, RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem, RelatonW3c::W3cBibliographicItem.
90 91 92 93 94 95 96 97 98 |
# File 'lib/relaton/db.rb', line 90 def fetch_std(code, year = nil, stdclass = nil, opts = {}) std = nil @registry.processors.each do |name, processor| std = name if processor.prefix == stdclass end std = standard_class(code) or return nil unless std check_bibliocache(code, year, opts, std) end |
#load_entry(key) ⇒ Hash
111 112 113 114 115 116 117 |
# File 'lib/relaton/db.rb', line 111 def load_entry(key) unless @local_db.nil? entry = @local_db[key] return entry if entry end @db[key] end |
#save_entry(key, value) ⇒ Object
122 123 124 125 |
# File 'lib/relaton/db.rb', line 122 def save_entry(key, value) @db.nil? || (@db[key] = value) @local_db.nil? || (@local_db[key] = value) end |
#to_xml ⇒ String
list all entries as a serialization
129 130 131 132 133 134 135 136 |
# File 'lib/relaton/db.rb', line 129 def to_xml db = @local_db || @db || return Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml| xml.documents do xml.parent.add_child db.all.join(" ") end end.to_xml end |