Class: SpecForge::Attribute::Regex

Inherits:
Attribute
  • Object
show all
Defined in:
lib/spec_forge/attribute/regex.rb

Overview

Represents a regular expression attribute using Ruby's Regexp class. This class handles the parsing of regex strings from YAML into actual Regexp objects, including support for standard regex flags (m, n, i, x).

Examples:

Basic usage in YAML

matcher: /pattern/i     # Case-insensitive matching
email: /@/              # Simple pattern matching
slug: /^[a-z0-9-]+$/    # Pattern with start/end anchors

With flags

description: /hello world/i   # Case-insensitive match using 'i' flag
text_block: /^hello\s+\w+/m   # Multi-line match using 'm' flag
mixed: /complex pattern/imx   # Multiple flags: case-insensitive, multi-line, extended mode

Constant Summary collapse

KEYWORD_REGEX =

Regular expression pattern that matches attribute keywords with this prefix Used for identifying this attribute type during parsing

Returns:

  • (Regexp)
/^\/(?<content>[\s\S]+)\/(?<flags>[mnix\s]*)$/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Regex

Creates a new regex attribute by parsing the input string

Parameters:

  • input (String)

    The regular expression pattern as a string



44
45
46
47
48
# File 'lib/spec_forge/attribute/regex.rb', line 44

def initialize(input)
  super

  @value = parse_regex(input)
end

Instance Attribute Details

#valueRegexp (readonly) Also known as: resolved, resolve

The parsed Regexp object

Returns:

  • (Regexp)


34
35
36
# File 'lib/spec_forge/attribute/regex.rb', line 34

def value
  @value
end