Class: FSymbol
Overview
CallerUtils
- Kyanite definitions
- Kyanite tests and examples
-
TestKyaniteFSymbols
- Usage
-
require ‘kyanite/fsymbol’
A FSymbol (“focusable Symbol”) is a comparable Symbol within a hierarchy. You can use it for classifications. In its values, it is limited to the values, which are defined in the hierarchy. FSymbols are comparable with <= >= <=>. A more specific FSymbol is larger than a more general FSymbol (because the specific FSymbol contains more information) E.g. if you define a hierarchy if animal species, you can say:
:insect.to_f_symbol <= :bee.to_f_symbol
FSymbols are equal to Symbols with the same name.
Constant Summary collapse
- @@instance_cache =
{}
- @@def_tree_cache =
nil
Instance Attribute Summary collapse
-
#childs ⇒ Object
Returns the value of attribute childs.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #<=(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #>=(other) ⇒ Object
-
#initialize(value, def_tree = nil) ⇒ FSymbol
constructor
A new instance of FSymbol.
- #inspect ⇒ Object
- #nil? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(value, def_tree = nil) ⇒ FSymbol
Returns a new instance of FSymbol.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kyanite/fsymbol.rb', line 29 def initialize( value, def_tree=nil) raise ArgumentError, 'First parameter (value) must not be nil!' if value.nil? @value = value if @@instance_cache[value] @childs = @@instance_cache[value].childs return @@instance_cache[value] end if def_tree.nil? def_tree = @@def_tree_cache else @@def_tree_cache = def_tree end raise ArgumentError, "FSymbol could not be created. No def_tree." if def_tree.nil? tree = def_tree.find(value) || nil raise ArgumentError, "FSymbol could not be created. Did not found value :#{value} in def_tree." if tree.nil? @childs = tree.all_child_keys @@instance_cache[value] = self self end |
Instance Attribute Details
#childs ⇒ Object
Returns the value of attribute childs.
16 17 18 |
# File 'lib/kyanite/fsymbol.rb', line 16 def childs @childs end |
#value ⇒ Object
Returns the value of attribute value.
15 16 17 |
# File 'lib/kyanite/fsymbol.rb', line 15 def value @value end |
Class Method Details
.instance_cache ⇒ Object
21 22 23 |
# File 'lib/kyanite/fsymbol.rb', line 21 def self.instance_cache @@instance_cache end |
Instance Method Details
#<=(other) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/kyanite/fsymbol.rb', line 83 def <=(other) return nil if other.nil? begin c = (self <=> other) (c == -1 || c == 0) rescue nil end end |
#<=>(other) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/kyanite/fsymbol.rb', line 63 def <=>(other) return nil if other.nil? other = other.to_fsymbol unless other.class == FSymbol return 0 if @value == other.value return -1 if @childs.include?(other.value) return 1 if other.childs.include?(@value) return nil end |
#==(other) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/kyanite/fsymbol.rb', line 73 def ==(other) return nil if other.nil? begin (self <=> other) == 0 rescue nil end end |
#>=(other) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/kyanite/fsymbol.rb', line 94 def >=(other) return nil if other.nil? begin c = (self <=> other) (c == 1 || c == 0) rescue nil end end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/kyanite/fsymbol.rb', line 58 def inspect @value.inspect end |
#nil? ⇒ Boolean
105 106 107 108 |
# File 'lib/kyanite/fsymbol.rb', line 105 def nil? return true if @value.nil? false end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/kyanite/fsymbol.rb', line 53 def to_s @value.to_s end |