Class: KLookup::Lookup::Radical
- Inherits:
-
Object
- Object
- KLookup::Lookup::Radical
- Defined in:
- lib/klookup/lookup_radical.rb
Overview
An abstract representation of radicals.
Constant Summary collapse
- @@data =
A class variable because we have class methods which need this.
KLookup::Lookup.default_handler
Class Method Summary collapse
-
.exist?(radical) ⇒ Boolean
Returns true if
radical
exists in the database. -
.handler ⇒ Object
Get handler used by this class.
-
.handler=(h) ⇒ Object
Set handler used by this class (see also Lookup.handler=).
-
.list(strokes = nil) ⇒ Object
Returns an array of radicals with
strokes
strokes. -
.strokes ⇒ Object
Return an array of how many strokes radicals can be made up of.
Instance Method Summary collapse
- #==(radical) ⇒ Object
-
#initialize(radical) ⇒ Radical
constructor
A new instance of Radical.
-
#to_s ⇒ Object
Returns a textual representation of a radical.
Constructor Details
#initialize(radical) ⇒ Radical
Returns a new instance of Radical.
18 19 20 21 22 23 |
# File 'lib/klookup/lookup_radical.rb', line 18 def initialize(radical) unless @@data.instance.is_radical?(radical) raise ArgumentError end @radical = radical.to_s end |
Class Method Details
.exist?(radical) ⇒ Boolean
Returns true if radical
exists in the database.
53 54 55 56 57 58 59 60 |
# File 'lib/klookup/lookup_radical.rb', line 53 def self.exist?(radical) begin new(radical) return true rescue ArgumentError return false end end |
.handler ⇒ Object
Get handler used by this class.
26 27 28 |
# File 'lib/klookup/lookup_radical.rb', line 26 def self.handler @@data end |
.handler=(h) ⇒ Object
Set handler used by this class (see also Lookup.handler=).
31 32 33 |
# File 'lib/klookup/lookup_radical.rb', line 31 def self.handler=(h) @@data = h end |
.list(strokes = nil) ⇒ Object
Returns an array of radicals with strokes
strokes. Without an argument, all radicals are returned.
42 43 44 45 46 47 48 49 50 |
# File 'lib/klookup/lookup_radical.rb', line 42 def self.list(strokes=nil) if strokes.nil? @@data.instance.radicals_by_strokes.values.flatten else raise ArgumentError unless strokes.respond_to?(:to_i) @@data.instance.radicals_by_strokes[strokes.to_i] end end |
.strokes ⇒ Object
Return an array of how many strokes radicals can be made up of.
36 37 38 |
# File 'lib/klookup/lookup_radical.rb', line 36 def self.strokes @@data.instance.stroke_count_list end |
Instance Method Details
#==(radical) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/klookup/lookup_radical.rb', line 62 def == (radical) unless radical.is_a? KLookup::Lookup::Radical radical = KLookup::Lookup::Radical.new(radical.to_s) end return true if radical.to_s == to_s false end |
#to_s ⇒ Object
Returns a textual representation of a radical.
71 72 73 |
# File 'lib/klookup/lookup_radical.rb', line 71 def to_s @radical end |