Class: Relaton::Db

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

Constant Summary collapse

SUPPORTED_GEMS =
%w[ isobib rfcbib gbbib ].freeze

Instance Method Summary collapse

Constructor Details

#initialize(global_cache, local_cache) ⇒ Db

Returns a new instance of Db.



9
10
11
12
13
14
15
16
# File 'lib/relaton/db.rb', line 9

def initialize(global_cache, local_cache)
  @bibdb = open_cache_biblio(global_cache)
  @local_bibdb = open_cache_biblio(local_cache)
  @bibdb_name = global_cache
  @local_bibdb_name = local_cache
  register_gems
  @registry = Relaton::Registry.instance
end

Instance Method Details

#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 rfcbib, ISO or IEC or IEV for isobib

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:

  • (String)

    Relaton XML serialisation of reference



36
37
38
39
# File 'lib/relaton/db.rb', line 36

def fetch(code, year = nil, opts = {})
  stdclass = standard_class(code) or return nil
  check_bibliocache(code, year, opts, stdclass)
end

#register_gemsObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/relaton/db.rb', line 18

def register_gems
  puts "[relaton] detecting backends:"
  SUPPORTED_GEMS.each do |b|
    puts b
    begin
      require b
    rescue LoadError
      puts "[relaton] backend #{b} not present"
    end
  end
end

#saveObject



41
42
43
44
# File 'lib/relaton/db.rb', line 41

def save
  save_cache_biblio(@bibdb, @bibdb_name)
  save_cache_biblio(@local_bibdb, @local_bibdb_name)
end