Class: Affiliation

Inherits:
ApplicationRecord show all
Defined in:
app/models/affiliation.rb

Class Method Summary collapse

Class Method Details

.find_fuzzy_by_name(name) ⇒ Object



14
15
16
# File 'app/models/affiliation.rb', line 14

def self.find_fuzzy_by_name(name)
  find_by(name: name) || Affiliation.where("name like '%#{name}%'").order(:code).first
end

.load_from_file(file) ⇒ Object

Affiliation file is loaded onto the servers via pransible into the shared folder



4
5
6
7
8
9
10
11
12
# File 'app/models/affiliation.rb', line 4

def self.load_from_file(file)
  affiliations = CSV.read(file, headers: true, skip_lines: /^JT_CF.*/)
  affiliations.each do |data|
    code = data["Dept"]
    if Affiliation.where(code: ).count == 0
      self.create(code: code, name: data["Department Descr"])
    end
  end  
end