Class: Relaton::Db
- Inherits:
-
Object
- Object
- Relaton::Db
- Defined in:
- lib/relaton/db.rb
Constant Summary collapse
- SUPPORTED_GEMS =
%w[isobib ietfbib gbbib iecbib nistbib].freeze
Instance Method Summary collapse
-
#docid_type(code) ⇒ Object
The document identifier class corresponding to the given code.
-
#fetch(code, year = nil, opts = {}) ⇒ String
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
- #fetched(key) ⇒ Object
-
#initialize(global_cache, local_cache) ⇒ Db
constructor
A new instance of Db.
- #load_entry(key) ⇒ Hash
- #register_gems ⇒ Object
- #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.
13 14 15 16 17 18 19 20 |
# File 'lib/relaton/db.rb', line 13 def initialize(global_cache, local_cache) register_gems @registry = Relaton::Registry.instance @db = open_cache_biblio(global_cache) @local_db = open_cache_biblio(local_cache, global: false) @db_name = global_cache @local_db_name = local_cache end |
Instance Method Details
#docid_type(code) ⇒ Object
The document identifier class corresponding to the given code
64 65 66 67 68 |
# File 'lib/relaton/db.rb', line 64 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 = {}) ⇒ String
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,
40 41 42 43 |
# File 'lib/relaton/db.rb', line 40 def fetch(code, year = nil, opts = {}) stdclass = standard_class(code) or return nil check_bibliocache(code, year, opts, stdclass) end |
#fetch_std(code, year = nil, stdclass = nil, opts = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/relaton/db.rb', line 45 def fetch_std(code, year = nil, stdclass = nil, opts = {}) std = nil @registry.processors.each do |name, processor| std = name if processor.prefix == stdclass end unless std std = standard_class(code) or return nil end check_bibliocache(code, year, opts, std) end |
#fetched(key) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/relaton/db.rb', line 56 def fetched(key) return @local_db.fetched key if @local_db return @db.fetched key if @db "" end |
#load_entry(key) ⇒ Hash
72 73 74 75 76 77 78 |
# File 'lib/relaton/db.rb', line 72 def load_entry(key) unless @local_db.nil? entry = @local_db[key] return entry if entry end @db[key] end |
#register_gems ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/relaton/db.rb', line 22 def register_gems puts "[relaton] Info: detecting backends:" SUPPORTED_GEMS.each do |b| # puts b begin require b rescue LoadError puts "[relaton] Error: backend #{b} not present" end end end |
#save_entry(key, value) ⇒ Object
83 84 85 86 |
# File 'lib/relaton/db.rb', line 83 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
90 91 92 93 94 95 96 97 |
# File 'lib/relaton/db.rb', line 90 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 |