module RGFA::FieldValidator

Methods to validate the string representations of the GFA fields data @api private

Constants

DATASTRING_VALIDATION_REGEXP

Validation regular expressions, derived from the GFA specification

Public Instance Methods

validate_gfa_field!(datatype, fieldname=nil) click to toggle source

Validates the string according to the provided datatype @param datatype [RGFA::Line::FIELD_DATATYPE] @param fieldname [#to_s] Fieldname to use in the error msg @raise [RGFA::FieldParser::FormatError] if the string does not match

the regexp for the provided datatype

@return [void] @api private

# File lib/rgfa/field_validator.rb, line 40
def validate_gfa_field!(datatype, fieldname=nil)
  regexp = DATASTRING_VALIDATION_REGEXP[datatype]
  raise RGFA::FieldParser::UnknownDatatypeError if regexp.nil?
  if (regexp !~ self)
    fieldname ||= "Value"
    raise RGFA::FieldParser::FormatError,
      "Wrong format for field #{fieldname}: \n"+
      "Content: #{self.inspect}\n"+
      "Datatype: #{datatype}\n"+
      "Expected regex: #{regexp}\n"
  end
end
validate_segment_name!() click to toggle source

Validates segment names, to check that they do not contain + or - followed by comma @raise [RGFA::FieldParser::FormatError] if the segment name is invalid @return [void] @api private

# File lib/rgfa/field_validator.rb, line 58
def validate_segment_name!
  if self =~ /.*[+-],.*/
    raise RGFA::FieldParser::FormatError,
    "Segment names are not allowed to contain +/- followed by comma "+
    "(found: #{self})"
  end
end