Class: RGFA::Line::Header
- Inherits:
-
RGFA::Line
- Object
- RGFA::Line
- RGFA::Line::Header
- Defined in:
- lib/rgfa/line/header.rb
Overview
A header line of a RGFA file
For examples on how to set the header data, see Headers.
Constant Summary collapse
- RECORD_TYPE =
:H
- REQFIELDS =
[]
- PREDEFINED_OPTFIELDS =
[:VN]
- DATATYPE =
{ :VN => :Z }
Constants inherited from RGFA::Line
DELAYED_PARSING_DATATYPES, DIRECTION, FIELD_DATATYPE, OPTFIELD_DATATYPE, ORIENTATION, RECORD_TYPES, RECORD_TYPE_LABELS, REQFIELD_DATATYPE, SEPARATOR
Instance Method Summary collapse
-
#add(fieldname, value, datatype = nil) ⇒ Object
Set a header value (multi-value compatible).
-
#merge(gfa_line) ⇒ self
private
Merge an additional Header line into this header line.
-
#split ⇒ Array<RGFA::Line::Header>
private
Split the header line into single-tag lines.
-
#tags ⇒ Array<(Symbol, Symbol, Object)>
private
Array of optional tags data.
Methods inherited from RGFA::Line
#==, #clone, #delete, #field_to_s, #fieldnames, #get, #get!, #get_datatype, #initialize, #method_missing, #optional_fieldnames, #real!, #record_type, #required_fieldnames, #respond_to?, #set, #set_datatype, subclass, #to_a, #to_rgfa_line, #to_s, #validate!, #validate_field!, #virtual?
Constructor Details
This class inherits a constructor from RGFA::Line
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RGFA::Line
Instance Method Details
#add(fieldname, value, datatype = nil) ⇒ Object
Set a header value (multi-value compatible).
If a field does not exist yet, set it to value. If it exists and it is a FieldArray, add the value to the field array. If it exists and it is not a field array, create a field array with the previous value and the new one
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rgfa/line/header.rb', line 28 def add(fieldname, value, datatype=nil) fieldname = fieldname.to_sym prev = get(fieldname) if prev.nil? set_datatype(fieldname, datatype) if datatype set(fieldname, value) return self elsif !prev.kind_of?(RGFA::FieldArray) prev = RGFA::FieldArray.new(get_datatype(fieldname), [prev]) set_datatype(fieldname, :J) set(fieldname,prev) end prev.push_with_validation(value, datatype, fieldname) return self end |
#merge(gfa_line) ⇒ self
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.
Merge an additional RGFA::Line::Header line into this header line.
85 86 87 88 89 90 |
# File 'lib/rgfa/line/header.rb', line 85 def merge(gfa_line) gfa_line.optional_fieldnames.each do |of| add(of, gfa_line.get(of), gfa_line.get_datatype(of)) end self end |
#split ⇒ Array<RGFA::Line::Header>
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.
Split the header line into single-tag lines.
If a tag is a FieldArray, this is splitted into multiple fields with the same fieldname.
72 73 74 75 76 77 78 79 |
# File 'lib/rgfa/line/header.rb', line 72 def split .map do |tagname, datatype, value| h = RGFA::Line::Header.new([], validate: @validate) h.set_datatype(tagname, datatype) h.set(tagname, value) h end end |
#tags ⇒ Array<(Symbol, Symbol, 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.
Array of optional tags data.
Returns the optional fields as an array of [fieldname, datatype, value] arrays. If a field is a FieldArray, this is splitted into multiple fields with the same fieldname.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rgfa/line/header.rb', line 51 def retval = [] optional_fieldnames.each do |of| value = get(of) if value.kind_of?(RGFA::FieldArray) value.each do |elem| retval << [of, value.datatype, elem] end else retval << [of, get_datatype(of), value] end end return retval end |