Class: Relaton::Db
- Inherits:
-
Object
- Object
- Relaton::Db
- Defined in:
- lib/relaton/db.rb
Instance Method Summary collapse
- #combine_doc(code, year, opts, stdclass) ⇒ Object
-
#docid_type(code) ⇒ Array
The document identifier class corresponding to the given code.
-
#fetch(code, year = nil, opts = {}) ⇒ NilClass, ...
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 = {}) ⇒ Object
-
#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) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/relaton/db.rb', line 37 def combine_doc(code, year, opts, stdclass) if (refs = code.split " + ").size > 1 reltype = "derivedFrom" reldesc = nil elsif (refs = code.split ", ").size > 1 reltype = "complements" reldesc = "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") refs[1..-1].each_with_object(doc) do |c, d| bib = check_bibliocache("#{ref}/#{c}", year, opts, stdclass) d.relation << RelatonBib::DocumentRelation.new( type: reltype, description: reldesc, bibitem: bib ) end end |
#docid_type(code) ⇒ Array
The document identifier class corresponding to the given code
76 77 78 79 80 |
# File 'lib/relaton/db.rb', line 76 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 = {}) ⇒ NilClass, ...
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,
29 30 31 32 33 34 35 |
# File 'lib/relaton/db.rb', line 29 def fetch(code, year = nil, opts = {}) stdclass = standard_class(code) || return cd = combine_doc code, year, opts, stdclass return cd if cd check_bibliocache(code, year, opts, stdclass) end |
#fetch_std(code, year = nil, stdclass = nil, opts = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/relaton/db.rb', line 63 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
84 85 86 87 88 89 90 |
# File 'lib/relaton/db.rb', line 84 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
95 96 97 98 |
# File 'lib/relaton/db.rb', line 95 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
102 103 104 105 106 107 108 109 |
# File 'lib/relaton/db.rb', line 102 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 |