Class: RGFA::FieldArray
Overview
Array representing multiple values of the same tag in different header lines
Defined Under Namespace
Classes: Error, TypeMismatchError
Instance Attribute Summary collapse
-
#datatype ⇒ Object
readonly
Returns the value of attribute datatype.
Instance Method Summary collapse
-
#default_gfa_datatype ⇒ Object
private
Default datatype, in this case :J.
-
#initialize(datatype, data = []) ⇒ FieldArray
constructor
A new instance of FieldArray.
-
#push_with_validation(value, type, fieldname = nil) ⇒ Object
Add a value to the array and validate.
-
#to_gfa_field(datatype: nil) ⇒ Object
private
Representation of the field array as JSON array, with two additional values: the datatype and a zero byte as “signature”.
-
#validate_gfa_field!(datatype, fieldname = nil) ⇒ Object
Run a datatype-specific validation on each element of the array.
Methods inherited from Array
#rgfa_field_array?, #to_byte_array, #to_cigar, #to_cigar_operation, #to_numeric_array, #to_oriented_segment, #to_rgfa, #to_rgfa_field_array, #to_rgfa_line, #to_segment_end
Constructor Details
#initialize(datatype, data = []) ⇒ FieldArray
Returns a new instance of FieldArray.
6 7 8 9 |
# File 'lib/rgfa/field_array.rb', line 6 def initialize(datatype, data = []) @datatype = datatype super(data) end |
Instance Attribute Details
#datatype ⇒ Object (readonly)
Returns the value of attribute datatype.
3 4 5 |
# File 'lib/rgfa/field_array.rb', line 3 def datatype @datatype end |
Instance Method Details
#default_gfa_datatype ⇒ 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.
Default datatype, in this case :J
19 20 21 |
# File 'lib/rgfa/field_array.rb', line 19 def default_gfa_datatype :J end |
#push_with_validation(value, type, fieldname = nil) ⇒ Object
Add a value to the array and validate
45 46 47 48 49 50 51 52 53 54 55 56 |
# 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) ⇒ 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.
Representation of the field array as JSON array, with two additional values: the datatype and a zero byte as “signature”.
27 28 29 30 31 |
# 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) ⇒ Object
Run a datatype-specific validation on each element of the array
13 14 15 |
# File 'lib/rgfa/field_array.rb', line 13 def validate_gfa_field!(datatype, fieldname=nil) each.validate_gfa_field!(@datatype, fieldname) end |