class Dagger::Generate::Regexp

Generate a value by collecting regexp matches for keys, and filling format strings.

_default.key:

- regexp:
    srckey:
      - regexp
      - ...
    ...
  string:
    - format string
    - ...

Public Instance Methods

process(sources) click to toggle source
# File lib/dagger/generate/regexp.rb, line 20
def process(sources)
  matches = {}
  sources.each do |key, regexps|
    matches.merge!(match_regexps(key, regexps))
  end
  update(dictionary: matches)
end

Private Instance Methods

match_regexps(key, regexps) → Hash click to toggle source

Match the value of a key agains regexps, returning the named captured data.

# File lib/dagger/generate/regexp.rb, line 35
def match_regexps(key, regexps)
  string = dictionary[key]

  array(regexps).each_with_object({}) do |regexp, matches|
    matchdata = ::Regexp.new(regexp).match(string)
    next if matchdata.nil?

    matches.merge!(matchdata.named_captures.transform_keys(&:to_sym))
  end
end