Class: OSU::Email
- Inherits:
-
Object
- Object
- OSU::Email
- 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
-
#email ⇒ Object
readonly
Returns the value of attribute email.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(email) ⇒ Email
constructor
A new instance of Email.
- #name_n ⇒ Object
Constructor Details
#initialize(email) ⇒ Email
Returns a new instance of Email.
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
#email ⇒ Object (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
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_n ⇒ Object
22 23 24 |
# File 'lib/osu/email.rb', line 22 def name_n VALID_EMAIL.match(email)["name_n"] end |