Method: Versionomy::Value#convert
- Defined in:
- lib/versionomy/value.rb
#convert(format_, convert_params_ = nil) ⇒ Object
Attempts to convert this value to the given format, and returns the resulting value.
Raises Versionomy::Errors::ConversionError if the value could not be converted.
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/versionomy/value.rb', line 294 def convert(format_, convert_params_=nil) if format_.kind_of?(::String) || format_.kind_of?(::Symbol) format_ = Format.get(format_) end return self if @_format == format_ from_schema_ = @_format.schema to_schema_ = format_.schema if from_schema_ == to_schema_ return Value.new(@_values, format_, convert_params_) end conversion_ = Conversion.get(from_schema_, to_schema_) if conversion_ conversion_.convert_value(self, format_, convert_params_) else standard_format_ = Format.get(:standard) conversion1_ = Conversion.get(from_schema_, standard_format_) conversion2_ = Conversion.get(standard_format_, to_schema_) if conversion1_ && conversion2_ value_ = conversion1_.convert_value(self, standard_format_, convert_params_) conversion2_.convert_value(value_, format_, convert_params_) else raise Errors::UnknownConversionError end end end |