Class: OSU::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/osu/email.rb

Overview

Validates an osu email. Can also strip a name.# from an osu email.

Defined Under Namespace

Classes: InvalidEmailError

Constant Summary collapse

VALID_EMAIL =
/\A(?<name_n>[a-z]([a-z-]*[a-z])?\.[1-9]\d*)@([a-z]+\.|)osu.edu\z/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ Email

Returns a new instance of Email.

Raises:



16
17
18
19
20
# File 'lib/osu/email.rb', line 16

def initialize(email)
  raise InvalidEmailError, email unless self.class.valid?(email)

  @email = email.downcase
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



14
15
16
# File 'lib/osu/email.rb', line 14

def email
  @email
end

Class Method Details

.valid?(email) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'lib/osu/email.rb', line 7

def self.valid?(email)
  case email
  when VALID_EMAIL then true
  else false
  end
end

Instance Method Details

#name_nObject



22
23
24
# File 'lib/osu/email.rb', line 22

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