Module: MetasploitDataModels::Match::Child

Overview

no_instance = MetasploitDataModels::Format.match('12')

Instance Method Summary collapse

Instance Method Details

#match(formatted_value) ⇒ Object

Creates a new instance of the extending class if MATCH_REGEXP, defined on the extending class, matches formatted_value.

Parameters:

  • formatted_value (#to_s)


26
27
28
29
30
31
32
33
34
# File 'lib/metasploit_data_models/match/child.rb', line 26

def match(formatted_value)
  instance = nil

  if match_regexp.match(formatted_value)
    instance = new(value: formatted_value)
  end

  instance
end

#match_regexpRegexp

Regular expression to match against for #match.

Returns:

  • (Regexp)

    Defaults to #regexp pinned with \A and \z.



39
40
41
# File 'lib/metasploit_data_models/match/child.rb', line 39

def match_regexp
  @match_regexp ||= /\A#{regexp}\z/
end

#regexpRegexp

Regular expression to match child as part of Parent.

Returns:

  • (Regexp)

    Default to REGEXP from the extending Class.



46
47
48
# File 'lib/metasploit_data_models/match/child.rb', line 46

def regexp
  self::REGEXP
end