Class: Relaton::Db
- Inherits:
-
Object
- Object
- Relaton::Db
- Defined in:
- lib/relaton/db.rb
Instance Method Summary collapse
-
#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
#docid_type(code) ⇒ Array
The document identifier class corresponding to the given code
52 53 54 55 56 |
# File 'lib/relaton/db.rb', line 52 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 |
# File 'lib/relaton/db.rb', line 29 def fetch(code, year = nil, opts = {}) stdclass = standard_class(code) || return check_bibliocache(code, year, opts, stdclass) end |
#fetch_std(code, year = nil, stdclass = nil, opts = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/relaton/db.rb', line 38 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
60 61 62 63 64 65 66 |
# File 'lib/relaton/db.rb', line 60 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
71 72 73 74 |
# File 'lib/relaton/db.rb', line 71 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
78 79 80 81 82 83 84 85 |
# File 'lib/relaton/db.rb', line 78 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 |