Class: KeyValueName::FloatMarshaler

Inherits:
MarshalerBase show all
Defined in:
lib/key_value_name/marshalers/float_marshaler.rb

Overview

Read and write float types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MarshalerBase

#to_comparable

Constructor Details

#initialize(format: '%g') ⇒ FloatMarshaler



8
9
10
# File 'lib/key_value_name/marshalers/float_marshaler.rb', line 8

def initialize(format: '%g')
  @format_string = format
end

Instance Attribute Details

#format_stringObject (readonly)

Returns the value of attribute format_string.



12
13
14
# File 'lib/key_value_name/marshalers/float_marshaler.rb', line 12

def format_string
  @format_string
end

Instance Method Details

#generate(value) ⇒ Object



22
23
24
# File 'lib/key_value_name/marshalers/float_marshaler.rb', line 22

def generate(value)
  format(format_string, value.to_s)
end

#matcherObject



14
15
16
# File 'lib/key_value_name/marshalers/float_marshaler.rb', line 14

def matcher
  /[-+]?[0-9]*\.?[0-9]+(?:e[-+]?[0-9]+)?/i
end

#parse(string) ⇒ Object



18
19
20
# File 'lib/key_value_name/marshalers/float_marshaler.rb', line 18

def parse(string)
  string.to_f
end