Class: GraphViz::Types::GvDouble

Inherits:
Common show all
Defined in:
lib/graphviz/types/gv_double.rb

Constant Summary collapse

FLOAT_MASK =
/[-+]?(?:[0-9]*\.[0-9]+|[0-9]+)/

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from GraphViz::Types::Common

Instance Method Details

#check(data) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
# File 'lib/graphviz/types/gv_double.rb', line 9

def check(data)
  if data.kind_of?(Numeric) or (data.is_a?(String) and FLOAT_MASK.match(data))
    return data
  end

  return nil if data.is_a?(String) and data.empty?

  raise DoubleException, "Invalid double value for `#{data}`"
end

#outputObject Also known as: to_gv, to_s



19
20
21
# File 'lib/graphviz/types/gv_double.rb', line 19

def output
  return @data.to_s.inspect.gsub( "\\\\", "\\" )
end

#to_fObject Also known as: to_ruby



23
24
25
# File 'lib/graphviz/types/gv_double.rb', line 23

def to_f
  @data.to_f
end