Class: MigemoDictCache
- Inherits:
-
Object
- Object
- MigemoDictCache
- Defined in:
- lib/migemo-dict.rb
Instance Method Summary collapse
-
#initialize(filename) ⇒ MigemoDictCache
constructor
A new instance of MigemoDictCache.
- #lookup(pattern) ⇒ Object
Constructor Details
#initialize(filename) ⇒ MigemoDictCache
Returns a new instance of MigemoDictCache.
97 98 99 100 |
# File 'lib/migemo-dict.rb', line 97 def initialize (filename) @dict = File.new(filename) @index = File.new(filename + ".idx").read.unpack "N*" end |
Instance Method Details
#lookup(pattern) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/migemo-dict.rb', line 112 def lookup (pattern) raise if pattern == nil pattern = pattern.downcase idx = @index.bsearch_first do |_idx| key, data = decompose(_idx) key <=> pattern end if idx key, data = decompose(@index[idx]) return data else nil end end |