Module: Recog::Fingerprint::RegexpFactory
- Defined in:
- lib/recog/fingerprint/regexp_factory.rb
Overview
Constant Summary collapse
- FLAG_MAP =
Currently, only options relating to case insensitivity and multiline/newline are supported. Because Recog's data is used by tools written in different languages like Ruby and Java, we currently support specifying them in a variety of ways. This map controls how they can be specified.
TODO: consider supporting only a simpler variant and require that tools that use Recog data translate accordingly
{ # multiline variations 'REG_DOT_NEWLINE' => Regexp::MULTILINE, 'REG_LINE_ANY_CRLF' => Regexp::MULTILINE, 'REG_MULTILINE' => Regexp::MULTILINE, # case variations 'REG_ICASE' => Regexp::IGNORECASE, 'IGNORECASE' => Regexp::IGNORECASE }.freeze
- DEFAULT_FLAGS =
0
Class Method Summary collapse
- .build(pattern, flags) ⇒ Regexp
-
.build_options(flags) ⇒ Fixnum
Convert string flag names as used in Recog XML into a Fixnum suitable for passing as the
options
parameter toRegexp.new
.
Class Method Details
.build(pattern, flags) ⇒ Regexp
32 33 34 35 |
# File 'lib/recog/fingerprint/regexp_factory.rb', line 32 def self.build(pattern, flags) = (flags) Regexp.new(pattern, ) end |
.build_options(flags) ⇒ Fixnum
Convert string flag names as used in Recog XML into a Fixnum suitable for
passing as the options
parameter to Regexp.new
43 44 45 46 47 48 49 50 |
# File 'lib/recog/fingerprint/regexp_factory.rb', line 43 def self.(flags) unsupported_flags = flags.reject { |flag| FLAG_MAP.key?(flag) } raise "Unsupported regular expression flags found: #{unsupported_flags.join(',')}. Must be one of: #{FLAG_MAP.keys.join(',')}" unless unsupported_flags.empty? flags.reduce(DEFAULT_FLAGS) do |sum, flag| sum | (FLAG_MAP[flag] || 0) end end |