2015-09-01 11:09:26 +03:00
|
|
|
class VolunteerTeam < ActiveRecord::Base
|
|
|
|
belongs_to :conference
|
2015-09-02 00:07:50 +03:00
|
|
|
has_many :volunteerships
|
|
|
|
has_many :volunteers, through: :volunteerships
|
2015-09-01 11:09:26 +03:00
|
|
|
|
|
|
|
validates :name, presence: true
|
|
|
|
validates :color, presence: true, format: {with: /\A#?[a-f0-9]{6}\z/i}
|
|
|
|
validates :description, presence: true
|
|
|
|
|
|
|
|
translates :name, :description
|
|
|
|
|
2015-09-02 00:07:50 +03:00
|
|
|
def include?(volunteer)
|
|
|
|
volunteers.include? volunteer
|
|
|
|
end
|
|
|
|
|
2015-09-01 11:09:26 +03:00
|
|
|
def color=(hex_triplet)
|
|
|
|
write_attribute :color, hex_triplet.gsub(/\A#/,'') if hex_triplet
|
|
|
|
end
|
|
|
|
|
|
|
|
def color
|
|
|
|
"##{read_attribute :color}"
|
|
|
|
end
|
|
|
|
end
|