Class: Spoom::Poset::Element

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

Overview

An element in a POSet : [E < Object]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Element

: (E value) -> void



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

#dfromsObject (readonly)

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



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

def dfroms
  @dfroms
end

#dtosObject (readonly)

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



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

def dtos
  @dtos
end

#fromsObject (readonly)

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



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

def froms
  @froms
end

#tosObject (readonly)

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



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

def tos
  @tos
end

#valueObject (readonly)

The value held by this element : E



138
139
140
# File 'lib/spoom/poset.rb', line 138

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object

: (untyped other) -> Integer?



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

#ancestorsObject

Direct and indirect ancestors of this element : -> Array



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

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

#childrenObject

Direct children of this element : -> Array



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

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

#descendantsObject

Direct and indirect descendants of this element : -> Array



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

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

#parentsObject

Direct parents of this element : -> Array



167
168
169
# File 'lib/spoom/poset.rb', line 167

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