class LIVR::Rules::String::Like

Public Class Methods

new(re_str, flags=nil) click to toggle source
# File lib/livr/rules/string.rb, line 126
def initialize(re_str, flags=nil)
  @re_str = re_str
  @flags = flags
end

Public Instance Methods

call(value, user_data, field_results) click to toggle source
# File lib/livr/rules/string.rb, line 131
def call(value, user_data, field_results)
  return if value.in? [nil, ""]
  return 'FORMAT_ERROR' unless is_primitive(value)

  value = value.to_s
  regexp = Regexp.compile(@re_str, @flags)

  unless regexp.match(value)
    return 'WRONG_FORMAT'
  end

  field_results << value

  return
end