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
120
121
122
# File 'lib/klookup/database_flatfile_radk.rb', line 107

def get_kanji(*radicals)
  kanji = nil
  if radicals.nil? or radicals.length == 0 or radicals.all? {|r| r.nil?}
    raise ArgumentError, "This method doesn't do that sort of thing."
  end
  radicals.flatten.each { |rad|
    raise ArgumentError, 'Radical does not exist' 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.


130
131
132
133
134
135
136
137
138
# File 'lib/klookup/database_flatfile_radk.rb', line 130

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.


125
126
127
# File 'lib/klookup/database_flatfile_radk.rb', line 125

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