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 |
# File 'lib/kyanite/fsymbol.rb', line 29 def initialize( value, def_tree=nil) raise ArgumentError, 'Value darf nicht nil sein!' 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 tree = def_tree.find(value) || nil raise ArgumentError, "FSymbol konnte nicht erzeugt werden. Value :#{value} nicht im Definitionstree gefunden." 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
82 83 84 85 86 87 88 89 90 |
# File 'lib/kyanite/fsymbol.rb', line 82 def <=(other) return nil if other.nil? begin c = (self <=> other) (c == -1 || c == 0) rescue nil end end |
#<=>(other) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/kyanite/fsymbol.rb', line 62 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
72 73 74 75 76 77 78 79 |
# File 'lib/kyanite/fsymbol.rb', line 72 def ==(other) return nil if other.nil? begin (self <=> other) == 0 rescue nil end end |
#>=(other) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/kyanite/fsymbol.rb', line 93 def >=(other) return nil if other.nil? begin c = (self <=> other) (c == 1 || c == 0) rescue nil end end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/kyanite/fsymbol.rb', line 57 def inspect @value.inspect end |
#nil? ⇒ Boolean
104 105 106 107 |
# File 'lib/kyanite/fsymbol.rb', line 104 def nil? return true if @value.nil? false end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/kyanite/fsymbol.rb', line 52 def to_s @value.to_s end |