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.
- #stroke_count ⇒ Object
-
#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.
57 58 59 60 61 62 63 64 |
# File 'lib/klookup/lookup_radical.rb', line 57 def self.exist?(radical) begin new(radical) return true rescue ArgumentError return false end end |
.handler ⇒ Object
Get handler used by this class.
30 31 32 |
# File 'lib/klookup/lookup_radical.rb', line 30 def self.handler @@data end |
.handler=(h) ⇒ Object
Set handler used by this class (see also Lookup.handler=).
35 36 37 |
# File 'lib/klookup/lookup_radical.rb', line 35 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.
46 47 48 49 50 51 52 53 54 |
# File 'lib/klookup/lookup_radical.rb', line 46 def self.list(strokes=nil) if strokes.nil? @@data.instance.find_radical else raise ArgumentError unless strokes.respond_to?(:to_i) @@data.instance.find_radical(:stroke=>strokes.to_i) end end |
.strokes ⇒ Object
Return an array of how many strokes radicals can be made up of.
40 41 42 |
# File 'lib/klookup/lookup_radical.rb', line 40 def self.strokes @@data.instance.radical_stroke_count end |
Instance Method Details
#==(radical) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/klookup/lookup_radical.rb', line 66 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 |
#stroke_count ⇒ Object
25 26 27 |
# File 'lib/klookup/lookup_radical.rb', line 25 def stroke_count @@data.instance.get_stroke_count(@radical) end |
#to_s ⇒ Object
Returns a textual representation of a radical.
75 76 77 |
# File 'lib/klookup/lookup_radical.rb', line 75 def to_s @radical end |