Class: ValidationHelperCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/fae/validation_helper_collection.rb

Instance Method Summary collapse

Instance Method Details

#emailObject



36
37
38
39
40
41
42
43
44
# File 'lib/fae/validation_helper_collection.rb', line 36

def email
  {
    allow_blank: true,
    format: {
      with: self.email_regex,
      message: 'is invalid'
    }
  }
end

#email_regexObject



7
8
9
# File 'lib/fae/validation_helper_collection.rb', line 7

def email_regex
  /\A\s*(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})[\s\/,;]*)+\z/
end

#slugObject

Complete Hash Validations



25
26
27
28
29
30
31
32
33
34
# File 'lib/fae/validation_helper_collection.rb', line 25

def slug
  {
    uniqueness: true,
    presence: true,
    format: {
      with: self.slug_regex,
      message: 'cannot have spaces or special characters'
    }
  }
end

#slug_regexObject



3
4
5
# File 'lib/fae/validation_helper_collection.rb', line 3

def slug_regex
  /\A[-_a-zA-Z0-9]+\z/
end

#urlObject



46
47
48
49
50
51
52
53
54
# File 'lib/fae/validation_helper_collection.rb', line 46

def url
  {
    allow_blank: true,
    format: {
      with: self.url_regex,
      message: 'is invalid'
    }
  }
end

#url_regexObject



11
12
13
# File 'lib/fae/validation_helper_collection.rb', line 11

def url_regex
  /\A(https?:\/\/)/
end

#youtube_regexObject



19
20
21
# File 'lib/fae/validation_helper_collection.rb', line 19

def youtube_regex
  /[a-zA-Z0-9_-]{11}/
end

#youtube_urlObject



66
67
68
69
70
71
72
73
74
# File 'lib/fae/validation_helper_collection.rb', line 66

def youtube_url
  {
    allow_blank: true,
    format: {
      with: self.youtube_regex,
      message: 'is invalid'
    }
  }
end

#zipObject



56
57
58
59
60
61
62
63
64
# File 'lib/fae/validation_helper_collection.rb', line 56

def zip
  {
    allow_blank: true,
    format: {
      with: self.zip_regex,
      message: 'is invalid'
    }
  }
end

#zip_regexObject



15
16
17
# File 'lib/fae/validation_helper_collection.rb', line 15

def zip_regex
  /\A(\d{5})?\z/
end