Class: JapaneseNames::Backend::Memory::Store
- Inherits:
-
Object
- Object
- JapaneseNames::Backend::Memory::Store
- Defined in:
- lib/japanese_names/backend/memory/store.rb
Overview
In-memory store of the Enamdict dictionary
Class Method Summary collapse
-
.find(kanji) ⇒ Object
Public: Finds kanji and/or kana regex strings in the dictionary via a structured query interface.
-
.store ⇒ Object
Public: The memoized dictionary instance.
Class Method Details
.find(kanji) ⇒ Object
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], …]
15 16 17 18 |
# 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 ⇒ Object
Public: The memoized dictionary instance.
21 22 23 24 25 26 27 28 29 |
# 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 |