Class: Cats::Core::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Cats::Core::User
- Defined in:
- app/models/cats/core/user.rb
Instance Method Summary collapse
- #add_detail(key, value) ⇒ Object
- #full_name ⇒ Object
- #hub ⇒ Object
- #remove_detail(key) ⇒ Object
- #stores ⇒ Object
- #validate_phone_number ⇒ Object
- #warehouse ⇒ Object
Instance Method Details
#add_detail(key, value) ⇒ Object
34 35 36 37 |
# File 'app/models/cats/core/user.rb', line 34 def add_detail(key, value) details[key] = value save! end |
#full_name ⇒ Object
54 55 56 |
# File 'app/models/cats/core/user.rb', line 54 def full_name "#{first_name} #{last_name}" end |
#hub ⇒ Object
28 29 30 31 32 |
# File 'app/models/cats/core/user.rb', line 28 def hub return unless details.key?("hub") Cats::Core::Location.find_by(id: details["hub"], location_type: Cats::Core::Location::HUB) end |
#remove_detail(key) ⇒ Object
39 40 41 42 |
# File 'app/models/cats/core/user.rb', line 39 def remove_detail(key) details.delete(key) save! end |
#stores ⇒ Object
22 23 24 25 26 |
# File 'app/models/cats/core/user.rb', line 22 def stores return unless details.key?("stores") Cats::Core::Store.where(id: details["stores"]) end |
#validate_phone_number ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'app/models/cats/core/user.rb', line 44 def validate_phone_number return unless phone_number.present? return if phone_number.length == 10 && /0\d{9}/.match(phone_number) return if phone_number.length == 12 && /251\d{9}/.match(phone_number) errors.add(:phone_number, "must be 10 or 12 digits and should match with local phone pattern") end |