Class: Manager
- Inherits:
-
Object
- Object
- Manager
- Defined in:
- lib/models/manager.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#phone ⇒ Object
Returns the value of attribute phone.
Instance Method Summary collapse
-
#initialize(id, name, email, phone) ⇒ Manager
constructor
A new instance of Manager.
- #valid_email? ⇒ Boolean
- #valid_phone? ⇒ Boolean
- #validate_null(name, value) ⇒ Object
Constructor Details
#initialize(id, name, email, phone) ⇒ Manager
Returns a new instance of Manager.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/models/manager.rb', line 6 def initialize(id, name, email, phone) validate_null("name", name) validate_null("email", email) validate_null("phone", phone) @id = id @name = name @email = email @phone = phone unless valid_email? raise ArgumentError, "Invalid email format" end unless valid_phone? raise ArgumentError, "Invalid phone number format" end end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
4 5 6 |
# File 'lib/models/manager.rb', line 4 def email @email end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/models/manager.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/models/manager.rb', line 4 def name @name end |
#phone ⇒ Object
Returns the value of attribute phone.
4 5 6 |
# File 'lib/models/manager.rb', line 4 def phone @phone end |
Instance Method Details
#valid_email? ⇒ Boolean
31 32 33 34 |
# File 'lib/models/manager.rb', line 31 def valid_email? email_regex = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i !!(email =~ email_regex) end |
#valid_phone? ⇒ Boolean
36 37 38 39 |
# File 'lib/models/manager.rb', line 36 def valid_phone? phone_regex = /\A(\+7|8)\s?\(?\d{3}\)?\s?\d{3}[\s-]?\d{2}[\s-]?\d{2}\z/ !!(phone =~ phone_regex) end |
#validate_null(name, value) ⇒ Object
25 26 27 28 29 |
# File 'lib/models/manager.rb', line 25 def validate_null(name, value) if value.nil? raise ArgumentError, "Argument '#{name}' cannot be null" end end |