Class: Relaton::Db
- Inherits:
-
Object
- Object
- Relaton::Db
- Defined in:
- lib/relaton/db.rb
Constant Summary collapse
- SUPPORTED_GEMS =
%w[ relaton_iso relaton_ietf relaton_gb relaton_iec relaton_nist relaton_itu ].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
-
#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.
15 16 17 18 19 20 21 22 |
# File 'lib/relaton/db.rb', line 15 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
66 67 68 69 70 |
# File 'lib/relaton/db.rb', line 66 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,
42 43 44 45 |
# File 'lib/relaton/db.rb', line 42 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
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/relaton/db.rb', line 47 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 |
#load_entry(key) ⇒ Hash
74 75 76 77 78 79 80 |
# File 'lib/relaton/db.rb', line 74 def load_entry(key) unless @local_db.nil? entry = @local_db[key] return entry if entry end @db[key] end |
#register_gems ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/relaton/db.rb', line 24 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
85 86 87 88 |
# File 'lib/relaton/db.rb', line 85 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
92 93 94 95 96 97 98 99 |
# File 'lib/relaton/db.rb', line 92 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 |