class RGFA::FieldArray

Array representing multiple values of the same tag in different header lines

Attributes

datatype[R]

Public Class Methods

new(datatype, data = []) click to toggle source

@param datatype [RGFA::Line::OPTFIELD_DATATYPE] the datatype to use

Calls superclass method
# File lib/rgfa/field_array.rb, line 6
def initialize(datatype, data = [])
  @datatype = datatype
  super(data)
end

Public Instance Methods

default_gfa_datatype() click to toggle source

Default datatype, in this case :J @api private

# File lib/rgfa/field_array.rb, line 19
def default_gfa_datatype
  :J
end
push_with_validation(value, type, fieldname=nil) click to toggle source

Add a value to the array and validate @raise [RGFA::FieldArray::TypeMismatchError] if the type

of the new value does not correspond to the type of
existing values

@param value [Object] the value to add @param type [RGFA::Line::OPTFIELD_DATATYPE, nil] the datatype to use;

if not +nil+, it will be checked that the specified datatype is the
same as for previous elements of the field array;
if +nil+, the value will be validated, according to the datatype
specified on field array creation

@param fieldname [Symbol] the field name to use for error messages

# File lib/rgfa/field_array.rb, line 45
def push_with_validation(value, type, fieldname=nil)
  if type.nil?
    value.validate_gfa_field!(@datatype, fieldname)
  elsif type != @datatype
    raise RGFA::FieldArray::TypeMismatchError,
      "Datatype mismatch error for field #{fieldname}:\n"+
      "value: #{value}\n"+
      "existing datatype: #{@datatype};\n"+
      "new datatype: #{type}"
  end
  self << value
end
to_gfa_field(datatype: nil) click to toggle source

Representation of the field array as JSON array, with two additional values: the datatype and a zero byte as “signature”. @param datatype [RGFA::Line::OPTFIELD_DATATYPE] (ignored, J is always used) @api private

# File lib/rgfa/field_array.rb, line 27
def to_gfa_field(datatype: nil)
  self << @datatype
  self << "\0"
  to_json
end
validate_gfa_field!(datatype, fieldname=nil) click to toggle source

Run a datatype-specific validation on each element of the array @param datatype [RGFA::Line::OPTFIELD_DATATYPE]

# File lib/rgfa/field_array.rb, line 13
def validate_gfa_field!(datatype, fieldname=nil)
  each.validate_gfa_field!(@datatype, fieldname)
end