class Versionomy::Conversion::Base
The base conversion class.
This base class defines the API for a conversion. All conversions must
define the method convert_value
documented here. Conversions
need not actually extend this base class, as long as they duck-type this
method. However, this base class does provide a few convenience methods
such as a sane implementation of inspect.
Public Class Methods
Create a conversion using a simple DSL. You can pass a block to the initializer that takes the same parameters as #convert_value, and the conversion will use that block to perform the conversion.
# File lib/versionomy/conversion/base.rb, line 58 def initialize(&block_) @_converter = block_ end
Public Instance Methods
Convert the given value to the given format and return the converted value.
The convert_params may be interpreted however the particular conversion wishes.
Raises Versionomy::Errors::ConversionError if the conversion failed.
# File lib/versionomy/conversion/base.rb, line 71 def convert_value(value_, format_, convert_params_=nil) if @_converter @_converter.call(value_, format_, convert_params_) else raise Errors::ConversionError, "Conversion not implemented" end end
Inspect this conversion.
# File lib/versionomy/conversion/base.rb, line 82 def inspect "#<#{self.class}:0x#{object_id.to_s(16)}>" end
The default #to_s implementation just calls inspect.
# File lib/versionomy/conversion/base.rb, line 89 def to_s inspect end