Class: Spoom::Poset::Element

Inherits:
Object
  • Object
show all
Extended by:
T::Generic
Includes:
Comparable
Defined in:
lib/spoom/poset.rb

Overview

An element in a POSet

Constant Summary collapse

E =
type_member { { upper: Object } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Element

: (E value) -> void



150
151
152
153
154
155
156
# File 'lib/spoom/poset.rb', line 150

def initialize(value)
  @value = value
  @dtos = T.let(Set.new, T::Set[Element[E]])
  @tos = T.let(Set.new, T::Set[Element[E]])
  @dfroms = T.let(Set.new, T::Set[Element[E]])
  @froms = T.let(Set.new, T::Set[Element[E]])
end

Instance Attribute Details

#dfromsObject (readonly)

Edges (direct and indirect) from this element to other elements in the same POSet : Set[Element]



147
148
149
# File 'lib/spoom/poset.rb', line 147

def dfroms
  @dfroms
end

#dtosObject (readonly)

Edges (direct and indirect) from this element to other elements in the same POSet : Set[Element]



147
148
149
# File 'lib/spoom/poset.rb', line 147

def dtos
  @dtos
end

#fromsObject (readonly)

Edges (direct and indirect) from this element to other elements in the same POSet : Set[Element]



147
148
149
# File 'lib/spoom/poset.rb', line 147

def froms
  @froms
end

#tosObject (readonly)

Edges (direct and indirect) from this element to other elements in the same POSet : Set[Element]



147
148
149
# File 'lib/spoom/poset.rb', line 147

def tos
  @tos
end

#valueObject (readonly)

The value held by this element : E



143
144
145
# File 'lib/spoom/poset.rb', line 143

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object

: (untyped other) -> Integer?



159
160
161
162
163
164
165
166
167
168
# File 'lib/spoom/poset.rb', line 159

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

#ancestorsObject

Direct and indirect ancestors of this element : -> Array



178
179
180
# File 'lib/spoom/poset.rb', line 178

def ancestors
  @tos.map(&:value)
end

#childrenObject

Direct children of this element : -> Array



184
185
186
# File 'lib/spoom/poset.rb', line 184

def children
  @dfroms.map(&:value)
end

#descendantsObject

Direct and indirect descendants of this element : -> Array



190
191
192
# File 'lib/spoom/poset.rb', line 190

def descendants
  @froms.map(&:value)
end

#parentsObject

Direct parents of this element : -> Array



172
173
174
# File 'lib/spoom/poset.rb', line 172

def parents
  @dtos.map(&:value)
end