Class: Versionomy::Conversion::Parsing::Builder

Inherits:
Object
  • Object
show all
Includes:
Blockenspiel::DSL
Defined in:
lib/versionomy/conversion/parsing.rb

Overview

Call methods of this class in the block passed to Versionomy::Conversion::Parsing#new to fine-tune the behavior of the converter.

Instance Method Summary collapse

Constructor Details

#initializeBuilder

:nodoc:



116
117
118
119
120
121
# File 'lib/versionomy/conversion/parsing.rb', line 116

def initialize  # :nodoc:
  @original_value_modifier = nil
  @string_modifier = nil
  @parse_params_generator = nil
  @unparse_params_modifier = nil
end

Instance Method Details

#_get_original_value_modifierObject

:nodoc:



172
173
174
# File 'lib/versionomy/conversion/parsing.rb', line 172

def _get_original_value_modifier  # :nodoc:
  @original_value_modifier
end

#_get_parse_params_generatorObject

:nodoc:



184
185
186
# File 'lib/versionomy/conversion/parsing.rb', line 184

def _get_parse_params_generator  # :nodoc:
  @parse_params_generator
end

#_get_string_modifierObject

:nodoc:



176
177
178
# File 'lib/versionomy/conversion/parsing.rb', line 176

def _get_string_modifier  # :nodoc:
  @string_modifier
end

#_get_unparse_params_modifierObject

:nodoc:



180
181
182
# File 'lib/versionomy/conversion/parsing.rb', line 180

def _get_unparse_params_modifier  # :nodoc:
  @unparse_params_modifier
end

#to_generate_parse_params(&block_) ⇒ Object

Provide a block that generates the params used to parse the new value. The block should take one parameter, the convert_params passed to convert_value (which may be nil). It should return the parse params that should be used.



129
130
131
# File 'lib/versionomy/conversion/parsing.rb', line 129

def to_generate_parse_params(&block_)
  @parse_params_generator = block_
end

#to_modify_original_value(&block_) ⇒ Object

Provide a block that can modify the original value prior to it being unparsed. The block should take two parameters: first, the original value to be converted, and second, the convert_params passed to convert_value (which may be nil). It should return the value to be unparsed, which may be the same as the value originally passed in. This method may fail-fast by raising a Versionomy::Errors::ConversionError if it determines that the value passed in cannot be converted as is.



155
156
157
# File 'lib/versionomy/conversion/parsing.rb', line 155

def to_modify_original_value(&block_)
  @original_value_modifier = block_
end

#to_modify_string(&block_) ⇒ Object

Provide a block that can modify the unparsed string prior to it being passed to the parser. The block should take two parameters: first, the string resulting from unparsing the old value, and second, the convert_params passed to convert_value (which may be nil). It should return the string to be parsed to get the new value.



167
168
169
# File 'lib/versionomy/conversion/parsing.rb', line 167

def to_modify_string(&block_)
  @string_modifier = block_
end

#to_modify_unparse_params(&block_) ⇒ Object

Provide a block that can modify the params used to unparse the old value. The block should take two parameters: first, the original unparse params from the old value (which may be nil), and second, the convert_params passed to convert_value (which may also be nil). It should return the unparse params that should actually be used.



141
142
143
# File 'lib/versionomy/conversion/parsing.rb', line 141

def to_modify_unparse_params(&block_)
  @unparse_params_modifier = block_
end