cirandas.net

ref: master

plugins/lattes_curriculum/lib/academic_info.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class AcademicInfo < ApplicationRecord

  belongs_to :person

  attr_accessible :lattes_url
  validate :lattes_url_validate?

  def lattes_url_validate?
    unless AcademicInfo.matches?(self.lattes_url)
      self.errors.add(:lattes_url, _(" is invalid."))
    end
  end

  def self.matches?(info)
    lattes = nil
    if info.class == String
      lattes = info
    elsif info.class == Hash
      lattes = info[:lattes_url]
    end
    return lattes.blank? || lattes =~ /^http:\/\/lattes.cnpq.br\/\d+$/
  end
end