Class: Spoom::Poset::Element
- Inherits:
-
Object
- Object
- Spoom::Poset::Element
- Includes:
- Comparable
- Defined in:
- lib/spoom/poset.rb
Overview
An element in a POSet
Instance Attribute Summary collapse
-
#dfroms ⇒ Object
readonly
Edges (direct and indirect) from this element to other elements in the same POSet.
-
#dtos ⇒ Object
readonly
Edges (direct and indirect) from this element to other elements in the same POSet.
-
#froms ⇒ Object
readonly
Edges (direct and indirect) from this element to other elements in the same POSet.
-
#tos ⇒ Object
readonly
Edges (direct and indirect) from this element to other elements in the same POSet.
-
#value ⇒ Object
readonly
The value held by this element.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#ancestors ⇒ Object
Direct and indirect ancestors of this element.
-
#children ⇒ Object
Direct children of this element.
-
#descendants ⇒ Object
Direct and indirect descendants of this element.
-
#initialize(value) ⇒ Element
constructor
A new instance of Element.
-
#parents ⇒ Object
Direct parents of this element.
Constructor Details
#initialize(value) ⇒ Element
Returns a new instance of Element.
145 146 147 148 149 150 151 |
# File 'lib/spoom/poset.rb', line 145 def initialize(value) @value = value @dtos = Set.new #: Set[Element[E]] @tos = Set.new #: Set[Element[E]] @dfroms = Set.new #: Set[Element[E]] @froms = Set.new #: Set[Element[E]] end |
Instance Attribute Details
#dfroms ⇒ Object (readonly)
Edges (direct and indirect) from this element to other elements in the same POSet
142 143 144 |
# File 'lib/spoom/poset.rb', line 142 def dfroms @dfroms end |
#dtos ⇒ Object (readonly)
Edges (direct and indirect) from this element to other elements in the same POSet
142 143 144 |
# File 'lib/spoom/poset.rb', line 142 def dtos @dtos end |
#froms ⇒ Object (readonly)
Edges (direct and indirect) from this element to other elements in the same POSet
142 143 144 |
# File 'lib/spoom/poset.rb', line 142 def froms @froms end |
#tos ⇒ Object (readonly)
Edges (direct and indirect) from this element to other elements in the same POSet
142 143 144 |
# File 'lib/spoom/poset.rb', line 142 def tos @tos end |
#value ⇒ Object (readonly)
The value held by this element
138 139 140 |
# File 'lib/spoom/poset.rb', line 138 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/spoom/poset.rb', line 154 def <=>(other) return unless other.is_a?(Element) return 0 if self == other if tos.include?(other) -1 elsif froms.include?(other) 1 end end |
#ancestors ⇒ Object
Direct and indirect ancestors of this element
173 174 175 |
# File 'lib/spoom/poset.rb', line 173 def ancestors @tos.map(&:value) end |
#children ⇒ Object
Direct children of this element
179 180 181 |
# File 'lib/spoom/poset.rb', line 179 def children @dfroms.map(&:value) end |
#descendants ⇒ Object
Direct and indirect descendants of this element
185 186 187 |
# File 'lib/spoom/poset.rb', line 185 def descendants @froms.map(&:value) end |
#parents ⇒ Object
Direct parents of this element
167 168 169 |
# File 'lib/spoom/poset.rb', line 167 def parents @dtos.map(&:value) end |