Created
April 12, 2011 05:40
-
-
Save zacclark/915004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FlatPerson | |
def initialize(person) | |
raise TypeMismatch unless person.class == Person | |
emp = person.employments_to_edit[0] || Employment.new | |
emp.company ||= Company.new | |
comp = emp.company | |
comp.cisco_dataset ||= CiscoDataset.new | |
cd = comp.cisco_dataset | |
ites = person.attendances_mapped[1] | |
summit = person.attendances_mapped[3] | |
emp.postal_address ||= PostalAddress.new | |
emp.assistant ||= Assistant.new | |
@prefix = person.prefix | |
@given_name = person.given_name | |
@surname = person.surname | |
@suffix = person.suffix | |
@title = (emp.current_title ? emp.current_title.title : "") | |
@company = emp.company.name | |
@address1 = emp.postal_address.address1 | |
@address2 = emp.postal_address.address2 | |
@city = emp.postal_address.city | |
@state = emp.postal_address.state | |
@postal_code = emp.postal_address.postal_code | |
@country = emp.postal_address.country | |
@email = emp.email | |
@assistant_email = emp.assistant.email | |
@company_duns = emp.company.duns_number | |
@sales_segment = (cd.sales_segment ? CiscoDataset::SalesSegments.rassoc(cd.sales_segment)[0] : "") | |
@industy = (cd.industry ? CiscoDataset::Industries.rassoc(cd.industry)[0] : "") | |
@theater = (cd.theater ? CiscoDataset::Theaters.rassoc(cd.theater)[0] : "") | |
@zone = cd.zone | |
@company_type = (cd.company_type ? CiscoDataset::CompanyTypes.rassoc(cd.company_type)[0] : "") | |
@ultimate_parent = (cd.ultimate_parent_id ? Company.find(cd.ultimate_parent_id).name : "") | |
@annual_revenue = emp.company.annual_revenue | |
@cisco_extra_information = (emp.cisco_extra_information && emp.cisco_extra_information.head_of_it ? "Yes" : "No") | |
@gender = (self.gender == 1 || self.gender == 2 ? Person::GenderChoices.rassoc(self.gender)[0] : "") | |
end | |
def method_missing(arg) | |
if eval("@#{arg}") | |
eval("@#{arg}") | |
end | |
end | |
end | |
class TypeMismatch < StandardError; end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment