Skip to content

Commit

Permalink
move non-activerecord models into domain_models dir
Browse files Browse the repository at this point in the history
  • Loading branch information
lazylester committed Oct 6, 2012
1 parent a5a2507 commit 4281323
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/domain_models/household_data_checker.rb
@@ -0,0 +1,44 @@
module HouseholdDataChecker
# not speed optimized, but intended only for admin, db checking
def self.with_no_head
includes(:perm_address, :temp_address, :clients).
all.
select(&:has_no_head?).
sort_by{|h| [(h.perm_address || Address.new), (h.temp_address || Address.new)]}
end

# not speed optimized, but intended only for admin, db checking
def self.with_multiple_heads
includes(:perm_address, :temp_address, :clients).
all.
select(&:has_multiple_heads?).
sort_by{|h| [(h.perm_address || Address.new), (h.temp_address || Address.new)]}
end

def self.with_no_addresses
where('perm_address_id IS NULL && temp_address_id IS NULL')
end

def has_head?
head_count > 0
end

def has_no_head?
head_count == 0
end

def has_single_head?
head_count == 1
end

# it's an error condition!
def has_multiple_heads?
head_count > 1
end

private
# to determine the error condition of multiple heads of household
def head_count
clients.map(&:headOfHousehold?).count(true)
end
end
5 changes: 5 additions & 0 deletions app/domain_models/household_qualdoc.rb
@@ -0,0 +1,5 @@
module HouseholdQualdoc
def belongs_to?(client)
household.clients.include?(client)
end
end
89 changes: 89 additions & 0 deletions app/domain_models/household_report.rb
@@ -0,0 +1,89 @@
module HouseholdReport

IncomeRanges = {
"Under $10,000" => (0..9999),
"$10,000 - $24,999" => (10000..24999),
"$25,000 - $34,999" => (25000..34999),
"$35,000 - $49,999" => (35000..49999),
"$50,000 and above" => (50000..9999999999999999999999999999),
"Unknown" => nil
}

def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
def blank_income_range_count
IncomeRanges.keys.inject({}){|hash,range| hash[range] = {:household_count => 0, :resident_count => 0}; hash}
end
end

def income_range
case income
when IncomeRanges["Under $10,000"]
"Under $10,000"
when IncomeRanges["$10,000 - $24,999"]
"$10,000 - $24,999"
when IncomeRanges["$25,000 - $34,999"]
"$25,000 - $34,999"
when IncomeRanges["$35,000 - $49,999"]
"$35,000 - $49,999"
when IncomeRanges["$50,000 and above"]
"$50,000 and above"
when nil
"Unknown"
end
end

def count_by_homeless
value = homeless? ? 1 : 0
{:homeless => value}
end

def new_or_continued_in_month(year,month)
date_of_first_distribution = distributions.sort_by(&:created_at).first.created_at
new = (date_of_first_distribution.year == year) && (date_of_first_distribution.month == month)
new ? :new : :continued
end

def new_in?(year,month)
new_or_continued_in_month(year,month) == :new
end

def family_structure
if clients.size == 1
"one person household"
elsif one_male_adult && child_count > 0
"single male parent"
elsif one_female_adult && child_count > 0
"single female parent"
elsif adult_count == 2 && child_count > 0
"couple w/ children"
elsif adult_count == 2 && child_count == 0
"couple w/o children"
else
"other family structure"
end
end

def one_male_adult
adults = clients.select(&:adult)
adult_males = adults.select(&:male)
(adult_count == 1) && (adult_males.length == 1)
end

def one_female_adult
adults = clients.select(&:adult)
adult_females = adults.select(&:female)
(adult_count == 1) && (adult_females.length == 1)
end

def adult_count
clients.select(&:adult).length
end

def child_count
clients.select(&:child).length
end
end

0 comments on commit 4281323

Please sign in to comment.