Sha256: 56285232964ad55eb9bce22c266c39bb285caf527ba5ddb26f966f57b783d8e4

Contents?: true

Size: 634 Bytes

Versions: 1

Compression:

Stored size: 634 Bytes

Contents

module OSU
  # Validates an osu email. Can also strip a name.# from an osu email.
  class Email
    VALID_EMAIL =
      /\A(?<name_n>[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)
      unless self.class.valid?(email)
        raise InvalidEmailError, 'Email must resemble name.#@osu.edu'
      end

      @email = email.downcase
    end

    def name_n
      VALID_EMAIL.match(email)['name_n']
    end

    class InvalidEmailError < ArgumentError; end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
osu_person-0.1.0 lib/osu/email.rb