Class: Cats::Core::User

Inherits:
ApplicationRecord show all
Defined in:
app/models/cats/core/user.rb

Instance Method Summary collapse

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_nameObject



54
55
56
# File 'app/models/cats/core/user.rb', line 54

def full_name
  "#{first_name} #{last_name}"
end

#hubObject



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

#storesObject



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_numberObject



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

#warehouseObject



16
17
18
19
20
# File 'app/models/cats/core/user.rb', line 16

def warehouse
  return unless details.key?("warehouse")

  Cats::Core::Location.find_by(id: details["warehouse"], location_type: Cats::Core::Location::WAREHOUSE)
end