Class: GFA::Field::Float

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

Constant Summary collapse

CODE =
:f
REGEX =
/[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/
NATIVE_FUN =
:to_f

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

Returns a new instance of Float.



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

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

Instance Method Details

#equivalent?(field) ⇒ Boolean

Returns:

  • (Boolean)


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

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

  super
end

#to_fObject



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

def to_f
  value
end

#to_iObject



10
11
12
# File 'lib/gfa/field/float.rb', line 10

def to_i
  value.to_i
end