Class: KLookup::Database::FlatFile
Overview
A singleton class to abstract RadK and KanjiDic.
Defined Under Namespace
Classes: KanjiDic, RadK
Instance Method Summary
collapse
open_resource, resource_path
Instance Method Details
#find_kanji(args = {}) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/klookup/database_flatfile.rb', line 58
def find_kanji(args={})
if not args.kind_of?(Hash)
raise ArgumentError, 'only takes a hash'
elsif (not args[:stroke].nil?) and (not args[:stroke].kind_of?(Integer))
raise ArgumentError, ':stroke must be an Integer'
end
get_kanji(args[:stroke], args[:radical])
end
|
#find_radical(args = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/klookup/database_flatfile.rb', line 31
def find_radical(args={})
raise ArgumentError, 'a hash or nothing' unless args.kind_of?(Hash)
if not args[:stroke]
RadK.instance.radicals_by_strokes.values.flatten
elsif not args[:stroke].kind_of?(Integer)
raise ArgumentError, ':stroke must be an Integer'
elsif radical_stroke_count.include?(args[:stroke])
RadK.instance.radicals_by_strokes[args[:stroke]]
else
[]
end
end
|
#get_meaning(kanji) ⇒ Object
87
88
89
90
91
|
# File 'lib/klookup/database_flatfile.rb', line 87
def get_meaning(kanji)
raise ArgumentError if kanji.chars.size > 1
raise ArgumentError unless is_kanji?(kanji)
KanjiDic.instance.get_meaning(kanji)
end
|
#get_radical(kanji) ⇒ Object
77
78
79
80
81
|
# File 'lib/klookup/database_flatfile.rb', line 77
def get_radical(kanji)
raise ArgumentError if kanji.chars.size > 1
raise ArgumentError unless is_kanji?(kanji)
RadK.instance.get_radicals(kanji)
end
|
#get_reading(kanji) ⇒ Object
82
83
84
85
86
|
# File 'lib/klookup/database_flatfile.rb', line 82
def get_reading(kanji)
raise ArgumentError if kanji.chars.size > 1
raise ArgumentError unless is_kanji?(kanji)
KanjiDic.instance.get_reading(kanji)
end
|
#get_stroke_count(*args) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/klookup/database_flatfile.rb', line 66
def get_stroke_count(*args)
begin
RadK.instance.get_strokes(*args)
rescue NoMethodError
begin
KanjiDic.instance.get_strokes(*args)
rescue NoMethodError
raise ArgumentError, 'character not found'
end
end
end
|
#is_kanji?(*args) ⇒ Boolean
92
93
94
|
# File 'lib/klookup/database_flatfile.rb', line 92
def is_kanji?(*args)
KanjiDic.instance.is_kanji?(*args)
end
|
#is_radical?(*args) ⇒ Boolean
95
96
97
|
# File 'lib/klookup/database_flatfile.rb', line 95
def is_radical?(*args)
RadK.instance.is_radical?(*args)
end
|
#radical_stroke_count(*args) ⇒ Object
21
22
23
|
# File 'lib/klookup/database_flatfile.rb', line 21
def radical_stroke_count(*args)
RadK.instance.stroke_count_list(*args)
end
|