Module: Validations

Defined in:
lib/validations.rb

Overview

some global validation tests using regular expression all what is related to regular expression checking should be concentrated here

Constant Summary collapse

MEL =

could be better the domain part can be : developpement-durable.gouv.fr or something.fr or wanadoo.fr or a.something@gmail.com so after the last dot, we have 2 or 3 characters all should be downcased but we accept capitals

/([^\W])([a-zA-Z0-9_\-]+)*(\.[a-zA-Z0-9_\-]+)*\@([a-zA-Z0-9_\-]+)(\.[a-zA-Z0-9_\-]+)*([\.]{1})([a-zA-Z]{2,3})/
CUSTOMER =
"Client"
PROJECT_MANAGER =
"Chargé d'affaire"
DATE =
/([0-9]{4}-[0-9]{2}-[0-9]{2})/
PROJECT_ID =
/[a-zA-Z][0-9]{1,2}[a-zA-Z]{1,2}[0-9]{1,4}/

Class Method Summary collapse

Class Method Details

.client_patternObject



16
17
18
# File 'lib/validations.rb', line 16

def self.client_pattern
  CUSTOMER
end

.date_reg_expObject

returns date regular expression



33
34
35
# File 'lib/validations.rb', line 33

def self.date_reg_exp
  DATE
end

.extract_client(str) ⇒ Object

returns from str a valid client mel if any



45
46
47
# File 'lib/validations.rb', line 45

def self.extract_client(str)
  build_and_extract(str,CUSTOMER,MEL)
end

.extract_project_description(str) ⇒ Object

returns project description



57
58
59
60
61
# File 'lib/validations.rb', line 57

def self.extract_project_description(str)
  exp = Regexp.new(" - #{CUSTOMER}")
  pos = str =~ exp
  str[0..pos]
end

.extract_project_manager(str) ⇒ Object

returns from str a valid project_manager mel if any



51
52
53
# File 'lib/validations.rb', line 51

def self.extract_project_manager(str)
  build_and_extract(str,PROJECT_MANAGER,MEL)
end

.mel_reg_expObject

returns exact mel regular expression used in shared_folders controller + in ajax view _new.js



27
28
29
# File 'lib/validations.rb', line 27

def self.mel_reg_exp
  Regexp.new("^#{MEL.source}$")
end

.project_id_reg_expObject

returns project id regular expression



39
40
41
# File 'lib/validations.rb', line 39

def self.project_id_reg_exp
  PROJECT_ID
end

.project_manager_patternObject



20
21
22
# File 'lib/validations.rb', line 20

def self.project_manager_pattern
  PROJECT_MANAGER
end