Class: Relaton::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton/db.rb

Instance Method Summary collapse

Constructor Details

#initialize(global_cache, local_cache) ⇒ Db

Returns a new instance of Db.

Parameters:

  • global_cache (String)

    directory of global DB

  • local_cache (String)

    directory of local 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.expand_path "../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

Parameters:

  • code (String)

Returns:

  • (Array)


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,

Parameters:

  • code (String)

    the ISO standard Code to look up (e.g. “ISO 9000”)

  • year (String) (defaults to: nil)

    the year the standard was published (optional)

  • opts (Hash) (defaults to: {})

    options; restricted to :all_parts if all-parts reference is required

Returns:

  • (NilClass, RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem, RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem)


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

Parameters:

  • code (String)
  • year (String, NilClass) (defaults to: nil)
  • stdclass (Symbol, NilClass) (defaults to: nil)
  • opts (Hash) (defaults to: {})


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

Parameters:

  • key (String)

Returns:

  • (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

Parameters:

  • key (String)
  • value (String)

    Bibitem xml serialisation.

Options Hash (value):

  • Bibitem (String)

    xml serialisation.



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_xmlString

list all entries as a serialization

Returns:

  • (String)


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