Class: Bright::SisApi::Base

Inherits:
Object show all
Defined in:
lib/bright/sis_apis/base.rb

Direct Known Subclasses

Aeries, BrightSis, InfiniteCampus, PowerSchool, Synergy, TSIS

Instance Method Summary collapse

Instance Method Details

#filter_students_by_params(students, params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bright/sis_apis/base.rb', line 5

def filter_students_by_params(students, params)
  total = params[:limit]
  count = 0
  found = []
  
  keys = (Student.attribute_names & params.keys.collect(&:to_sym))
  puts "filtering on #{keys.join(",")}"
  students.each do |student|
    break if total and count >= total
    
    should = (keys).all? do |m|
      student.send(m) =~ Regexp.new(Regexp.escape(params[m]), Regexp::IGNORECASE)
    end
    count += 1 if total and should
    found << student if should
  end
  found
end