Class: Versionomy::Format::Delimiter::SymbolFieldBuilder
- Inherits:
-
Object
- Object
- Versionomy::Format::Delimiter::SymbolFieldBuilder
- Includes:
- Blockenspiel::DSL
- Defined in:
- lib/versionomy/format/delimiter.rb
Overview
This class defines methods that can be called from the block passed to Versionomy::Format::Delimiter::Builder#field if the field is of symbolic type.
Instance Method Summary collapse
-
#initialize(recognizers_, field_, default_opts_) ⇒ SymbolFieldBuilder
constructor
:nodoc:.
-
#recognize_regexp(value_, regexp_, canonical_, opts_ = {}, &block_) ⇒ Object
Recognize a symbolic value represented by a particular regular expression.
-
#recognize_regexp_map(opts_ = {}, &block_) ⇒ Object
Recognize a set of symbolic values, each represented by a particular regular expression, but all sharing the same delimiters and options.
Constructor Details
#initialize(recognizers_, field_, default_opts_) ⇒ SymbolFieldBuilder
:nodoc:
585 586 587 588 589 |
# File 'lib/versionomy/format/delimiter.rb', line 585 def initialize(recognizers_, field_, default_opts_) # :nodoc: @recognizers = recognizers_ @field = field_ @default_opts = default_opts_ end |
Instance Method Details
#recognize_regexp(value_, regexp_, canonical_, opts_ = {}, &block_) ⇒ Object
Recognize a symbolic value represented by a particular regular expression. The regular expression must be passed as a string. E.g. use “[a-z]+” instead of /[a-z]+/. The “canonical” parameter indicates the canonical syntax for the value, for use in unparsing.
Using the opts parameter, you can override any of the field’s overall parsing options.
601 602 603 |
# File 'lib/versionomy/format/delimiter.rb', line 601 def recognize_regexp(value_, regexp_, canonical_, opts_={}, &block_) @recognizers << Delimiter::RegexpSymbolRecognizer.new(@field, value_, regexp_, canonical_, @default_opts.merge(opts_)) end |
#recognize_regexp_map(opts_ = {}, &block_) ⇒ Object
Recognize a set of symbolic values, each represented by a particular regular expression, but all sharing the same delimiters and options. Use this instead of repeated calls to recognize_regexp for better performance.
Using the opts parameter, you can override any of the field’s overall parsing options.
In the block, you should call methods of Versionomy::Format::Delimiter::MappingSymbolBuilder to map values to regular expression representations.
618 619 620 |
# File 'lib/versionomy/format/delimiter.rb', line 618 def recognize_regexp_map(opts_={}, &block_) @recognizers << Delimiter::MappingSymbolRecognizer.new(@field, @default_opts.merge(opts_), &block_) end |