Class: KLookup::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/klookup/database.rb

Overview

Database access modules:

  • FlatFile

  • Unihan

Direct Known Subclasses

FlatFile, Unihan

Defined Under Namespace

Classes: FlatFile, Unihan

Class Method Summary collapse

Class Method Details

.open_resource(path) ⇒ Object

Opens a resource.

Priority: LOOKUP_PATH environment variable, Gem load path.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/klookup/database.rb', line 29

def self.open_resource(path)
  # Choose a directory
  env=ENV['KLOOKUP_PATH']
  if env and env != ''
    dir=env+'/klookup'
  else
    begin
      gem 'klookup'
      dir=Gem.datadir 'klookup'
    rescue NameError
      raise IOError, 'Could not find resource %s' % path
    end
  end

  # Open a file
  file = open("#{dir}/#{path}")
  if block_given?
    yield file
  else
    return file
  end
end