module OSU # Validates an osu email. Can also strip a name.# from an osu email. class Email VALID_EMAIL = /\A(?[a-z]([a-z-]*[a-z])?\.[1-9]\d*)@([a-z]+\.|)osu.edu\z/i def self.valid?(email) case email when VALID_EMAIL then true else false end end attr_reader :email def initialize(email) raise InvalidEmailError, email unless self.class.valid?(email) @email = email.downcase end def name_n VALID_EMAIL.match(email)['name_n'] end # Raised when a string is an invalid email class InvalidEmailError < ArgumentError def initialize(email) super( "#{email} is not a valid OSU email. It must resemble name\.\#\@osu.edu" ) end end end end