A simple DSL to keep it short and simple, declarations to define the structure, and imperative code to handle that which can’t easily be declared. Just a rough sketch, but wouldn’t this be easier than half functional XML Schema?
validate do
email.optional
phone.optional
im_handle.optional
raise "Must specify at least one means of contact" unless
email || phone || im_handle
address.required do
street.required
city.required
state.optional
country.optional :default=>"US"
raise "State required for all addresses in the US" if
country == "US" && !state
raise "Zipcode does not match the rest of the address" if
valid_zipcode?(street, city, state, country, zipcode)
end
end