Module: Rordash::RegexUtil
- Defined in:
- lib/rordash/regex_util.rb
Constant Summary collapse
- EMAIL_MATCH =
URI::MailTo::EMAIL_REGEXP
- POSTAL_CODE_MATCH =
/[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d/.freeze
- DOTTED_INDEX_MATCH =
/\w+\[\d+\]/.freeze
- URI_MATCH =
URI::DEFAULT_PARSER.make_regexp.freeze
- TYPE =
{ email: EMAIL_MATCH, uri: URI_MATCH, postal_code: POSTAL_CODE_MATCH, dotted_index: DOTTED_INDEX_MATCH }.freeze
Class Method Summary collapse
- .match(type, value) ⇒ Object
- .match?(type, value) ⇒ Boolean
- .replace(type, value, replacement) ⇒ Object
Class Method Details
.match(type, value) ⇒ Object
22 23 24 |
# File 'lib/rordash/regex_util.rb', line 22 def match(type, value) TYPE[type].match(value) end |
.match?(type, value) ⇒ Boolean
18 19 20 |
# File 'lib/rordash/regex_util.rb', line 18 def match?(type, value) TYPE[type].match?(value) end |
.replace(type, value, replacement) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/rordash/regex_util.rb', line 26 def replace(type, value, replacement) return value unless value.is_a?(String) regex = TYPE[type] return value if regex.nil? value.sub(regex, replacement) end |