Class: Peanuts::Converter::Convert_float
- Inherits:
-
Convert_string
- Object
- Peanuts::Converter
- Convert_string
- Peanuts::Converter::Convert_float
- Defined in:
- lib/peanuts/converters.rb
Overview
A float.
- Specifier
-
:float
Options
:precision
-
Floating point precision.
In addition accepts all options of Convert_string
.
Instance Method Summary collapse
- #from_xml(string) ⇒ Object
-
#initialize(options) ⇒ Convert_float
constructor
A new instance of Convert_float.
- #to_xml(int) ⇒ Object
Methods inherited from Peanuts::Converter
create, create!, lookup, lookup!
Constructor Details
#initialize(options) ⇒ Convert_float
Returns a new instance of Convert_float.
173 174 175 176 177 |
# File 'lib/peanuts/converters.rb', line 173 def initialize() super @precision = [:precision] @format = @precision ? "%f.#{@precision}" : '%f' end |
Instance Method Details
#from_xml(string) ⇒ Object
183 184 185 |
# File 'lib/peanuts/converters.rb', line 183 def from_xml(string) (string = super(string)) && string.to_f end |
#to_xml(int) ⇒ Object
179 180 181 |
# File 'lib/peanuts/converters.rb', line 179 def to_xml(int) super(int && sprintf(@format, int)) end |