Skip to content

Instantly share code, notes, and snippets.

@djgraham
Created May 4, 2010 21:14
Show Gist options
  • Save djgraham/390005 to your computer and use it in GitHub Desktop.
Save djgraham/390005 to your computer and use it in GitHub Desktop.
# I wrote this as a method for formatting group numbers to go into a pdf holiday voucher..
# its messy but it works..
#
# Results:
# X adult(s), Y child(ren) and Z infant(s)
#
# rules: -
# - pluralization hacks in case of 1 of each of them.
# - only show children and infants if they're > 0
# - at least one adult is always present
#
# examples...
#
# 5 adults, 2 children and 1 infant
# 1 adult and 2 infants
# 2 adults and 1 child
# 1 adult
def pdf_total_in_group(number_of_adults, number_of_children = nil, number_of_infants = nil)
tmp = "#{number_of_adults} adult"
tmp += "s" if number_of_adults != 1
if number_of_children.to_i > 0 && number_of_infants.to_i > 0
tmp += ", "
else
if number_of_children.to_i >0 || number_of_infants.to_i > 0
tmp += " and "
end
end
tmp += "#{number_of_children} child#{'ren' if number_of_children.to_i!=1}" if number_of_children.to_i > 0
if number_of_children.to_i > 0 && number_of_infants.to_i > 0
tmp += " and "
end
tmp += "#{number_of_infants} infant#{'s' if number_of_infants.to_i!=1} (under 2 at time of travel)" if number_of_infants.to_i > 0
tmp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment