Class: RGFA::SegmentInfo Private

Inherits:
Array show all
Defined in:
lib/rgfa/segment_info.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A segment or segment name plus an additional boolean attribute

This class shall not be initialized directly.

Direct Known Subclasses

OrientedSegment, SegmentEnd

Defined Under Namespace

Classes: InvalidAttributeError, InvalidSizeError

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#default_gfa_datatype, #rgfa_field_array?, #to_byte_array, #to_cigar, #to_cigar_operation, #to_gfa_field, #to_numeric_array, #to_oriented_segment, #to_rgfa, #to_rgfa_field_array, #to_rgfa_line, #to_segment_end, #validate_gfa_field!

Class Method Details

.invert(attribute) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the other attribute value.

Parameters:

  • attribute (Symbol)

    an attribute value

Returns:

  • (Symbol)

    the other attribute value



70
71
72
73
74
75
76
77
# 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

Instance Method Details

#<=>(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compare the segment names and attributes of two instances

Parameters:

Returns:

  • (Boolean)


101
102
103
# File 'lib/rgfa/segment_info.rb', line 101

def <=>(other)
  to_s <=> other.to_segment_info(self.class).to_s
end

#==(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compare the segment names and attributes of two instances

Parameters:

Returns:

  • (Boolean)


93
94
95
# File 'lib/rgfa/segment_info.rb', line 93

def ==(other)
  to_s == other.to_segment_info(self.class).to_s
end

#attributeSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the attribute.

Returns:



47
48
49
# File 'lib/rgfa/segment_info.rb', line 47

def attribute
  self[1]
end

#attribute=(value) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the attribute

Parameters:

  • value (Symbol)

    the attribute

Returns:



54
55
56
# File 'lib/rgfa/segment_info.rb', line 54

def attribute=(value)
  self[1]=(value)
end

#attribute_invertedSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the other possible value of the attribute.

Returns:

  • (Symbol)

    the other possible value of the attribute



59
60
61
# File 'lib/rgfa/segment_info.rb', line 59

def attribute_inverted
  self.class::ATTR[self.class::ATTR[0] == self[1] ? 1 : 0]
end

#invert_attributeRGFA::SegmentInfo

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns same segment, inverted attribute.

Returns:



64
65
66
# File 'lib/rgfa/segment_info.rb', line 64

def invert_attribute
  self.class.new([self[0], self.attribute_inverted])
end

#nameSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the segment name.

Returns:

  • (Symbol)

    the segment name



42
43
44
# 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

#segmentSymbol, RGFA::Line::Segment

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the segment instance or name.

Returns:



30
31
32
# File 'lib/rgfa/segment_info.rb', line 30

def segment
  self[0]
end

#segment=(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the segment

Parameters:

Returns:

  • Symbol, RGFA::Line::Segment] value



37
38
39
# File 'lib/rgfa/segment_info.rb', line 37

def segment=(value)
  self[0]=value
end

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns name of the segment and attribute.

Returns:

  • (String)

    name of the segment and attribute



80
81
82
# File 'lib/rgfa/segment_info.rb', line 80

def to_s
  "#{name}#{attribute}"
end

#to_symSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns name of the segment and attribute.

Returns:

  • (Symbol)

    name of the segment and attribute



85
86
87
# File 'lib/rgfa/segment_info.rb', line 85

def to_sym
  to_s.to_sym
end

#validate!void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

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

Raises:



17
18
19
20
21
22
23
24
25
26
27
# 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