class JapaneseNames::Backend::Memory::Store
In-memory store of the Enamdict
dictionary
Public Class Methods
find(kanji)
click to toggle source
Public: Finds kanji and/or kana regex strings in the dictionary via a structured query interface.
kanji - (String, Array) Value or array of values of the kanji name to match.
Returns the dict entries as an Array of Arrays [[kanji, kana, flags], …]
# File lib/japanese_names/backend/memory/store.rb, line 15 def find(kanji) kanji = Array(kanji) store.values_at(*kanji).reject(&:nil?).inject(&:+) || [] end
store()
click to toggle source
Public: The memoized dictionary instance.
# File lib/japanese_names/backend/memory/store.rb, line 21 def store @store ||= JapaneseNames::Util::Kernel.deep_freeze( File.open(filepath, 'r:utf-8').each_with_object({}) do |line, hash| ary = line.chop.split('|') hash[ary[0]] ||= [] hash[ary[0]] << ary end ) end
Private Class Methods
filepath()
click to toggle source
Internal: Returns the filepath to the enamdict.min file.
# File lib/japanese_names/backend/memory/store.rb, line 34 def filepath File.join(JapaneseNames.root, 'bin/enamdict.min') end