/*******************************************************************************
 * Copyright (c) 2016 University of York
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * Contributors:
 *     Horacio Hoyos - Initial API and implementation
 *******************************************************************************/
 
rule Member2Male
    transform s : Families!Member
    to t : Persons!Male {

        guard : not s.isFemale()

        t.fullName = s.firstName + ' ' + s.familyName();
    }

rule Member2Female
    transform s : Families!Member
    to t : Persons!Female {

        guard : s.isFemale()

        t.fullName = s.firstName + ' ' + s.familyName();
    }

operation Families!Member familyName() : String {
    if (self.familyFather.isDefined()) {
        return self.familyFather.lastName;
    }
    else if (self.familyMother.isDefined()) {
        return self.familyMother.lastName;
    }
    else if (self.familySon.isDefined()) {
        return self.familySon.lastName;
    }
    else {
        return self.familyDaughter.lastName;
    }
}

operation Families!Member isFemale() : Boolean {
    if (self.familyMother.isDefined() or self.familyDaughter.isDefined()) {
        return true;
    }
    else {
        return false;
    }
}
