Class: Spoom::Poset::Element

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Sig
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

Returns a new instance of Element.



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

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)

Returns the value of attribute dfroms.



149
150
151
# File 'lib/spoom/poset.rb', line 149

def dfroms
  @dfroms
end

#dtosObject (readonly)

Returns the value of attribute dtos.



149
150
151
# File 'lib/spoom/poset.rb', line 149

def dtos
  @dtos
end

#fromsObject (readonly)

Returns the value of attribute froms.



149
150
151
# File 'lib/spoom/poset.rb', line 149

def froms
  @froms
end

#tosObject (readonly)

Returns the value of attribute tos.



149
150
151
# File 'lib/spoom/poset.rb', line 149

def tos
  @tos
end

#valueObject (readonly)

Returns the value of attribute value.



145
146
147
# File 'lib/spoom/poset.rb', line 145

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



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

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



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

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

#childrenObject



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

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

#descendantsObject



192
193
194
# File 'lib/spoom/poset.rb', line 192

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

#parentsObject



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

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