mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
39 lines
1.2 KiB
Ruby
39 lines
1.2 KiB
Ruby
class Income < ApplicationRecord
|
|
scope :by_designation, -> { all.map { |income| [income.designation, income] }.to_h }
|
|
scope :by_slug, -> { all.map { |income| [income.slug, income] }.to_h }
|
|
|
|
include FriendlyId
|
|
|
|
friendly_id :designation, use: [:slugged]
|
|
|
|
def self.to_designation(income)
|
|
return "Economically Disadvantaged - N" if income.blank? or income.nil?
|
|
|
|
case income
|
|
in /Free\s*Lunch|Reduced\s*Lunch|Low\s*Income|Reduced\s*price\s*lunch|true|1|^Yes$/i
|
|
"Economically Disadvantaged - Y"
|
|
in /Not\s*Eligible|false|0|^No$/i
|
|
"Economically Disadvantaged - N"
|
|
in %r{^#*N/*A$|Unknown|Income}i
|
|
"Unknown"
|
|
else
|
|
puts "************************************"
|
|
puts "******** ERROR **********"
|
|
puts ""
|
|
puts "Error parsing Income column. '#{income}' is not a known value. Halting execution"
|
|
puts ""
|
|
puts "************************************"
|
|
exit
|
|
end
|
|
end
|
|
|
|
LABELS = {
|
|
"Economically Disadvantaged - Y" => "Economically Disadvantaged",
|
|
"Economically Disadvantaged - N" => "Not Economically Disadvantaged",
|
|
"Unknown" => "Unknown"
|
|
}
|
|
|
|
def label
|
|
LABELS[designation]
|
|
end
|
|
end
|