Class: GFA::Field::NumArray
Constant Summary
collapse
- CODE =
:B
- REGEX =
/[cCsSiIf](,[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+/
- NATIVE_FUN =
:to_a
Constants inherited
from GFA::Field
CODES, TYPES
Instance Attribute Summary
Attributes inherited from GFA::Field
#value
Instance Method Summary
collapse
Methods inherited from GFA::Field
#!~, #==, [], #code, code_class, #eql?, #hash, name_class, #native_fun, #regex, #to_native, #to_s, #type, #~
Constructor Details
#initialize(f) ⇒ NumArray
Returns a new instance of NumArray.
6
7
8
9
|
# File 'lib/gfa/field/numarray.rb', line 6
def initialize(f)
GFA.assert_format(f, regex, "Bad #{type}")
@value = f
end
|
Instance Method Details
#array ⇒ Object
Also known as:
to_a
19
20
21
|
# File 'lib/gfa/field/numarray.rb', line 19
def array
@array ||= value[2..-1].split(',').map(&modifier_fun)
end
|
#equivalent?(field) ⇒ Boolean
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/gfa/field/numarray.rb', line 38
def equivalent?(field)
return true if eql?(field)
if field.respond_to?(:to_a)
field.to_a.map(&modifier_fun) == array
elsif size == 1 && field.respond_to?(modifier_fun)
field.send(modifier_fun) == first
else
false
end
end
|
#modifier ⇒ Object
11
12
13
|
# File 'lib/gfa/field/numarray.rb', line 11
def modifier
value[0]
end
|
#modifier_fun ⇒ Object
15
16
17
|
# File 'lib/gfa/field/numarray.rb', line 15
def modifier_fun
modifier == 'f' ? :to_f : :to_i
end
|
#number_type ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/gfa/field/numarray.rb', line 29
def number_type
{
c: 'int8_t', C: 'uint8_t',
s: 'int16_t', S: 'uint16_t',
i: 'int32_t', I: 'uint32_t',
f: 'float'
}[modifier.to_sym]
end
|