Class: KLookup::Database::FlatFile::RadK

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/klookup/database_flatfile_radk.rb

Overview

Access to RADKFILE (mappings from radicals to kanji).

Defined Under Namespace

Classes: MalformedDatabaseException

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#radicals_by_strokesObject (readonly)

Returns the value of attribute radicals_by_strokes.



19
20
21
# File 'lib/klookup/database_flatfile_radk.rb', line 19

def radicals_by_strokes
  @radicals_by_strokes
end

#stroke_count_listObject (readonly)

Returns the value of attribute stroke_count_list.



18
19
20
# File 'lib/klookup/database_flatfile_radk.rb', line 18

def stroke_count_list
  @stroke_count_list
end

Instance Method Details

#get_kanji(*radicals) ⇒ Object

Returns a list of kanji corresponding to given radicals.



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/klookup/database_flatfile_radk.rb', line 107

def get_kanji(*radicals)
  kanji = nil
  radicals.flatten.each { |rad|
    raise ArgumentError unless @records[rad.to_s]
    current_kanji = @records[rad.to_s][:kanji]
    if kanji==nil
      kanji = current_kanji
    else
      kanji &= current_kanji
    end
  }
  kanji.to_a
end

#get_radicals(kanji) ⇒ Object

Returns a list of radicals corresponding to a kanji.



127
128
129
130
131
132
133
134
135
# File 'lib/klookup/database_flatfile_radk.rb', line 127

def get_radicals(kanji)
  radicals = []
  @records.each { |radical,data|
    if data[:kanji].include? kanji
      radicals << radical
    end
  }
  radicals
end

#get_strokes(radical) ⇒ Object

Returns the number of strokes corresponding to a radical.



122
123
124
# File 'lib/klookup/database_flatfile_radk.rb', line 122

def get_strokes(radical)
  @records[radical][:strokes]
end

#is_radical?(radical) ⇒ Boolean

Tests if a radical exists.

Returns:

  • (Boolean)


99
100
101
102
103
104
# File 'lib/klookup/database_flatfile_radk.rb', line 99

def is_radical?(radical)
  return false unless radical.respond_to?(:to_s)
  return false if radical.to_s.chars.length != 1
  return false if @records[radical.to_s].nil?
  return true
end