Class: ExcADG::VStateData::Key
- Inherits:
-
Object
- Object
- ExcADG::VStateData::Key
- Includes:
- Comparable
- Defined in:
- lib/excadg/vstate_data.rb
Overview
class to support comparison and Arrays operations
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#vertex ⇒ Object
readonly
Returns the value of attribute vertex.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(name: nil, vertex: nil) ⇒ Key
constructor
A new instance of Key.
- #to_s ⇒ Object
Constructor Details
#initialize(name: nil, vertex: nil) ⇒ Key
Returns a new instance of Key.
17 18 19 20 21 22 23 24 |
# File 'lib/excadg/vstate_data.rb', line 17 def initialize name: nil, vertex: nil raise 'name or vertex are required' if name.nil? && vertex.nil? Assertions.is_a?(vertex, Vertex) unless vertex.nil? @name = name @vertex = vertex end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/excadg/vstate_data.rb', line 15 def name @name end |
#vertex ⇒ Object (readonly)
Returns the value of attribute vertex.
15 16 17 |
# File 'lib/excadg/vstate_data.rb', line 15 def vertex @vertex end |
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/excadg/vstate_data.rb', line 27 def <=> other return nil unless (other.is_a? self.class) || (is_a? other.class) # no mutual fields to compare return nil if (@vertex.nil? && other.name.nil?) || (@name.nil? && other.vertex.nil?) # name takes preference @name.nil? || other.name.nil? ? @vertex <=> other.vertex : @name <=> other.name end |
#eql?(other) ⇒ Boolean
36 37 38 |
# File 'lib/excadg/vstate_data.rb', line 36 def eql? other (self <=> other)&.zero? || false end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/excadg/vstate_data.rb', line 40 def to_s (@name || @vertex).to_s end |