Class: KeyValueName::FloatMarshaler
- Inherits:
-
MarshalerBase
- Object
- MarshalerBase
- KeyValueName::FloatMarshaler
- Defined in:
- lib/key_value_name/marshalers/float_marshaler.rb
Overview
Read and write float types.
Instance Attribute Summary collapse
-
#format_string ⇒ Object
readonly
Returns the value of attribute format_string.
Instance Method Summary collapse
- #generate(value) ⇒ Object
-
#initialize(format: '%g') ⇒ FloatMarshaler
constructor
A new instance of FloatMarshaler.
- #matcher ⇒ Object
- #parse(string) ⇒ Object
Methods inherited from MarshalerBase
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_string ⇒ Object (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 |
#matcher ⇒ Object
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 |