Class: GFA::Field::Hex

Inherits:
GFA::Field show all
Defined in:
lib/gfa/field/hex.rb

Constant Summary collapse

CODE =
:H
REGEX =
/[0-9A-F]+/
NATIVE_FUN =
:to_i

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) ⇒ Hex

Returns a new instance of Hex.



6
7
8
9
# File 'lib/gfa/field/hex.rb', line 6

def initialize(f)
  GFA.assert_format(f, regex, "Bad #{type}")
  @value = f
end

Instance Method Details

#equivalent?(field) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/gfa/field/hex.rb', line 19

def equivalent?(field)
  if field.is_a? GFA::Field::NumArray
    return field.size == 1 && field.first.to_i == value
  end

  super
end

#to_fObject



15
16
17
# File 'lib/gfa/field/hex.rb', line 15

def to_f
  to_i.to_f
end

#to_iObject



11
12
13
# File 'lib/gfa/field/hex.rb', line 11

def to_i
  value.to_i(16)
end