class Person
Attributes
Public Class Methods
Source
# File lib/models/person/person.rb, line 50 def self.parse_string(string) data = string.split(',') hash = {} data.each do |x| pair = x.strip.split(':') if pair[0] && !pair[0].strip.empty? && pair[1] then hash[pair[0].strip] = pair[1].strip + (pair[2] ? ":#{pair[2].strip}" : '') else raise ArgumentError, "Wrong string format" end end hash end
returning hash
Source
# File lib/models/person/person.rb, line 32 def self.valid_email?(email) email.nil? || email == "" || email =~ /^[\w+_.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ end
email validation
Source
# File lib/models/person/person.rb, line 27 def self.valid_git?(git) git.nil? || git == "" || git =~ %r{^https?://github\.com/[a-zA-Z0-9_\-]+$} end
git link validation
Source
# File lib/models/person/person.rb, line 37 def self.valid_name?(name) name =~ /^[А-ЯЁ][а-яё]{1,}(-[А-ЯЁ][а-яё]{1,})?$/ end
names validation
Source
# File lib/models/person/person.rb, line 17 def self.valid_phone_number?(phone_number) phone_number.nil? || phone_number == "" || phone_number =~ /^(?:\+7|8)[\s-]?(?:\(?\d{3}\)?[\s-]?)\d{3}[\s-]?\d{2}[\s-]?\d{2}$/ end
phone number validation
Source
# File lib/models/person/person.rb, line 22 def self.valid_telegram?(telegram) telegram.nil? || telegram == "" || telegram =~ /@[a-zA-Z0-9_]{5,}$/ end
telegram validation
Public Instance Methods
Source
# File lib/models/person/person.rb, line 10 def validate? self.validate_git? end
validate git
Source
# File lib/models/person/person.rb, line 5 def validate_git? !self.git.nil? end
checking for git availability
Protected Instance Methods
Source
# File lib/models/person/person.rb, line 42 def git=(git) unless self.class.valid_git?(git) raise ArgumentError, "Wrong git link format" end @git = git end
git setter