1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/models/contact_network.rb
2019-09-07 00:26:19 +05:00

39 lines
760 B
Ruby

# frozen_string_literal: true
class ContactNetwork < ApplicationRecord
CODENAME_RE = /\A[a-z][a-z0-9]*(_[a-z0-9]+)*\z/.freeze
FORMAT_RE = /\A[^[:space:]]+(.*[^[:space:]]+)?\z/.freeze
################
# Associations #
################
has_many :contacts
###############
# Validations #
###############
validates :codename,
presence: true,
length: { in: 3..36 },
format: CODENAME_RE,
uniqueness: { case_sensitive: false }
validates :name,
presence: true,
length: { in: 1..255 },
format: FORMAT_RE
###########
# Methods #
###########
def to_param
codename
end
def communicable?
%w[email telegram_id].include? codename
end
end