Class: Lingo::Language::LexicalHash

Inherits:
Object
  • Object
show all
Defined in:
lib/lingo/language/lexical_hash.rb

Overview

Die Klasse LexicalHash ermöglicht den Zugriff auf die Lingodatenbanken. Im Gegensatz zur Klasse Database, welche nur Strings als Ergebnis zurück gibt, wird hier als Ergebnis ein Array von Lexical-Objekten zurück gegeben.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (LexicalHash) initialize(id, lingo)

A new instance of LexicalHash



43
44
45
46
# File 'lib/lingo/language/lexical_hash.rb', line 43

def initialize(id, lingo)
  @wc  = lingo.database_config(id).fetch('def-wc', LA_UNKNOWN)
  @src = Database.open(id, lingo)
end

Class Method Details

+ (Object) open(*args)



37
38
39
40
41
# File 'lib/lingo/language/lexical_hash.rb', line 37

def self.open(*args)
  yield lexical_hash = new(*args)
ensure
  lexical_hash.close if lexical_hash
end

Instance Method Details

- (Object) [](key)



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/lingo/language/lexical_hash.rb', line 52

def [](key)
  rec = @src[key = Unicode.downcase(key)] or return

  res = rec.map { |str|
    case str
      when /^\*\d+$/           then str
      when /^#(.)$/            then Lexical.new(key, $1)
      when /^([^#]+?)\s*#(.)$/ then Lexical.new($1,  $2)
      when /^([^#]+)$/         then Lexical.new($1, @wc)
      else                          str
    end
  }

  res.compact!
  res.sort!
  res.uniq!

  res
end

- (Object) close



48
49
50
# File 'lib/lingo/language/lexical_hash.rb', line 48

def close
  @src.close
end