Class: JEDICT::DictionaryProxy

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

Instance Method Summary collapse

Constructor Details

#initialize(filename, eager_load) ⇒ DictionaryProxy

Returns a new instance of DictionaryProxy.



42
43
44
45
# File 'lib/jedict.rb', line 42

def initialize filename, eager_load
	@filename = filename 
	@dic = eager_load ? JEDICT::load_file(filename) : nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &blck) ⇒ Object



37
38
39
40
# File 'lib/jedict.rb', line 37

def method_missing sym, *args, &blck
	return @dic.send(sym, *args, &blck) if @dic && @dic.respond_to?(sym)
	super
end

Instance Method Details

#countObject



47
48
49
# File 'lib/jedict.rb', line 47

def count 
	@count ||= (@dic && @dic.length) || JEDICT::load_file(@filename, Parser::Count.new)
end

#each_entry(&blck) ⇒ Object



51
52
53
54
# File 'lib/jedict.rb', line 51

def each_entry &blck
	raise "Block expected" unless blck
	JEDICT::load_file @filename, Parser::Entry.new(blck)
end