class RGFA::SegmentInfo

A segment or segment name plus an additional boolean attribute

This class shall not be initialized directly. @api private

Public Class Methods

invert(attribute) click to toggle source

@param [Symbol] attribute an attribute value @return [Symbol] the other attribute value

# File lib/rgfa/segment_info.rb, line 70
def self.invert(attribute)
  i = self::ATTR.index(attribute.to_sym)
  if i.nil?
    raise RGFA::SegmentInfo::InvalidAttributeError,
      "Invalid attribute (#{self[1].inspect})"
  end
  return self::ATTR[i-1]
end

Public Instance Methods

<=>(other) click to toggle source

Compare the segment names and attributes of two instances

@param [RGFA::SegmentInfo] other the other instance @return [Boolean]

# File lib/rgfa/segment_info.rb, line 101
def <=>(other)
  to_s <=> other.to_segment_info(self.class).to_s
end
==(other) click to toggle source

Compare the segment names and attributes of two instances

@param [RGFA::SegmentInfo] other the other instance @return [Boolean]

# File lib/rgfa/segment_info.rb, line 93
def ==(other)
  to_s == other.to_segment_info(self.class).to_s
end
attribute() click to toggle source

@return [Symbol] the attribute

# File lib/rgfa/segment_info.rb, line 47
def attribute
  self[1]
end
attribute=(value) click to toggle source

Set the attribute @param value [Symbol] the attribute @return [Symbol] value

# File lib/rgfa/segment_info.rb, line 54
def attribute=(value)
  self[1]=(value)
end
attribute_inverted() click to toggle source

@return [Symbol] the other possible value of the attribute

# File lib/rgfa/segment_info.rb, line 59
def attribute_inverted
  self.class::ATTR[self.class::ATTR[0] == self[1] ? 1 : 0]
end
invert_attribute() click to toggle source

@return [RGFA::SegmentInfo] same segment, inverted attribute

# File lib/rgfa/segment_info.rb, line 64
def invert_attribute
  self.class.new([self[0], self.attribute_inverted])
end
name() click to toggle source

@return [Symbol] the segment name

# File lib/rgfa/segment_info.rb, line 42
def name
  self[0].kind_of?(RGFA::Line::Segment) ? self[0].name : self[0].to_sym
end
segment() click to toggle source

@return [Symbol, RGFA::Line::Segment] the segment instance or name

# File lib/rgfa/segment_info.rb, line 30
def segment
  self[0]
end
segment=(value) click to toggle source

Set the segment @param value [Symbol, RGFA::Line::Segment] the segment instance or name @return Symbol, RGFA::Line::Segment] value

# File lib/rgfa/segment_info.rb, line 37
def segment=(value)
  self[0]=value
end
to_s() click to toggle source

@return [String] name of the segment and attribute

# File lib/rgfa/segment_info.rb, line 80
def to_s
  "#{name}#{attribute}"
end
to_sym() click to toggle source

@return [Symbol] name of the segment and attribute

# File lib/rgfa/segment_info.rb, line 85
def to_sym
  to_s.to_sym
end
validate!() click to toggle source

Check that the elements of the array are compatible with the definition.

@!macro [new] segment_info_validation_errors

@raise [RGFA::SegmentInfo::InvalidSizeError] if size is not 2
@raise [RGFA::SegmentInfo::InvalidAttributeError] if second element
  is not a valid info

@return [void]

# File lib/rgfa/segment_info.rb, line 17
def validate!
  if size != 2
    raise RGFA::SegmentInfo::InvalidSizeError,
      "Wrong n of elements, 2 expected (#{inspect})"
  end
  if !self.class::ATTR.include?(self[1])
    raise RGFA::SegmentInfo::InvalidAttributeError,
      "Invalid attribute (#{self[1].inspect})"
  end
  return nil
end