chore: refactor code to put logic into models

rpp-main
Nelson Jovel 2 years ago
parent b983f1e144
commit 6365cad71b

@ -4,4 +4,14 @@ class Ell < ApplicationRecord
include FriendlyId
friendly_id :designation, use: [:slugged]
def self.to_designation(ell)
case ell
in /lep student 1st year|LEP student not 1st year|EL Student First Year|LEP\s*student/i
"ELL"
in /Does not apply/i
"Not ELL"
else
"Unknown"
end
end
end

@ -11,7 +11,7 @@ class Gender < ApplicationRecord
2
when /Another\s*Gender|Gender Identity not listed above|3|7/i
4 # We categorize any self reported gender as non-binary
when /Non-Binary|N|4/i
when /Non-Binary|^N|4/i
4
when /Prefer not to disclose|6/i
99

@ -5,4 +5,15 @@ class Income < ApplicationRecord
include FriendlyId
friendly_id :designation, use: [:slugged]
def self.to_designation(income)
case income
in /Free\s*Lunch|Reduced\s*Lunch|Low\s*Income|Reduced\s*price\s*lunch/i
"Economically Disadvantaged - Y"
in /Not\s*Eligible/i
"Economically Disadvantaged - N"
else
"Unknown"
end
end
end

@ -4,11 +4,13 @@ class Race < ApplicationRecord
has_many :students, through: :student_races
friendly_id :designation, use: [:slugged]
# TODO: look for alaska native
# Todo: split up possibilities by first a comma and then the word and
def self.qualtrics_code_from(word)
case word
when /Native\s*American|American\s*Indian|Alaskan\s*Native|1/i
1
when /Asian|Pacific\s*Island|2/i
when /Asian|Pacific\s*Island|Hawaiian|2/i
2
when /Black|African\s*American|3/i
3

@ -4,4 +4,14 @@ class Sped < ApplicationRecord
include FriendlyId
friendly_id :designation, use: [:slugged]
def self.to_designation(sped)
case sped
in /active/i
"Special Education"
in /^NA$|^#NA$/i
"Unknown"
else
"Not Special Education"
end
end
end

@ -153,14 +153,7 @@ class SurveyItemValues
end
def income
@income ||= case raw_income
in /Free\s*Lunch|Reduced\s*Lunch|Low\s*Income/i
"Economically Disadvantaged - Y"
in /Not\s*Eligible/i
"Economically Disadvantaged - N"
else
"Unknown"
end
@income ||= Income.to_designation(raw_income)
end
def raw_ell
@ -168,14 +161,7 @@ class SurveyItemValues
end
def ell
@ell ||= case raw_ell
in /lep student 1st year|LEP student not 1st year|EL Student First Year/i
"ELL"
in /Does not apply/i
"Not ELL"
else
"Unknown"
end
@ell ||= Ell.to_designation(raw_ell)
end
def raw_sped
@ -183,14 +169,7 @@ class SurveyItemValues
end
def sped
@sped ||= case raw_sped
in /active/i
"Special Education"
in /^NA$|^#NA$/i
"Unknown"
else
"Not Special Education"
end
@sped ||= Sped.to_designation(raw_sped)
end
def value_from(pattern:)

Loading…
Cancel
Save