Class: Slk::Models::Profile

Inherits:
Data
  • Object
show all
Defined in:
lib/slk/models/profile.rb

Overview

Composite model representing a Slack user profile, merged from users.profile.get + users.info + team.profile.get schema.

custom_fields is an Array<ProfileField>. resolved_users is a mutable Hash<user_id, Profile> populated by ProfileResolver one level deep for type:user fields (e.g. Supervisor).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#custom_fieldsObject (readonly)

Returns the value of attribute custom_fields

Returns:

  • (Object)

    the current value of custom_fields



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def custom_fields
  @custom_fields
end

#deletedObject (readonly)

Returns the value of attribute deleted

Returns:

  • (Object)

    the current value of deleted



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def deleted
  @deleted
end

#display_nameObject (readonly)

Returns the value of attribute display_name

Returns:

  • (Object)

    the current value of display_name



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def display_name
  @display_name
end

#emailObject (readonly)

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def email
  @email
end

#first_nameObject (readonly)

Returns the value of attribute first_name

Returns:

  • (Object)

    the current value of first_name



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def first_name
  @first_name
end

#home_team_nameObject (readonly)

Returns the value of attribute home_team_name

Returns:

  • (Object)

    the current value of home_team_name



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def home_team_name
  @home_team_name
end

#image_urlObject (readonly)

Returns the value of attribute image_url

Returns:

  • (Object)

    the current value of image_url



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def image_url
  @image_url
end

#is_adminObject (readonly)

Returns the value of attribute is_admin

Returns:

  • (Object)

    the current value of is_admin



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def is_admin
  @is_admin
end

#is_botObject (readonly)

Returns the value of attribute is_bot

Returns:

  • (Object)

    the current value of is_bot



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def is_bot
  @is_bot
end

#is_externalObject (readonly)

Returns the value of attribute is_external

Returns:

  • (Object)

    the current value of is_external



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def is_external
  @is_external
end

#is_ownerObject (readonly)

Returns the value of attribute is_owner

Returns:

  • (Object)

    the current value of is_owner



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def is_owner
  @is_owner
end

#last_nameObject (readonly)

Returns the value of attribute last_name

Returns:

  • (Object)

    the current value of last_name



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def last_name
  @last_name
end

#phoneObject (readonly)

Returns the value of attribute phone

Returns:

  • (Object)

    the current value of phone



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def phone
  @phone
end

#presenceObject (readonly)

Returns the value of attribute presence

Returns:

  • (Object)

    the current value of presence



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def presence
  @presence
end

#pronounsObject (readonly)

Returns the value of attribute pronouns

Returns:

  • (Object)

    the current value of pronouns



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def pronouns
  @pronouns
end

#real_nameObject (readonly)

Returns the value of attribute real_name

Returns:

  • (Object)

    the current value of real_name



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def real_name
  @real_name
end

#resolved_usersObject (readonly)

Returns the value of attribute resolved_users

Returns:

  • (Object)

    the current value of resolved_users



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def resolved_users
  @resolved_users
end

#sectionsObject (readonly)

Returns the value of attribute sections

Returns:

  • (Object)

    the current value of sections



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def sections
  @sections
end

#start_dateObject (readonly)

Returns the value of attribute start_date

Returns:

  • (Object)

    the current value of start_date



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def start_date
  @start_date
end

#status_emojiObject (readonly)

Returns the value of attribute status_emoji

Returns:

  • (Object)

    the current value of status_emoji



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def status_emoji
  @status_emoji
end

#status_expirationObject (readonly)

Returns the value of attribute status_expiration

Returns:

  • (Object)

    the current value of status_expiration



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def status_expiration
  @status_expiration
end

#status_textObject (readonly)

Returns the value of attribute status_text

Returns:

  • (Object)

    the current value of status_text



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def status_text
  @status_text
end

#team_idObject (readonly)

Returns the value of attribute team_id

Returns:

  • (Object)

    the current value of team_id



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def team_id
  @team_id
end

#titleObject (readonly)

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def title
  @title
end

#tzObject (readonly)

Returns the value of attribute tz

Returns:

  • (Object)

    the current value of tz



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def tz
  @tz
end

#tz_labelObject (readonly)

Returns the value of attribute tz_label

Returns:

  • (Object)

    the current value of tz_label



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def tz_label
  @tz_label
end

#tz_offsetObject (readonly)

Returns the value of attribute tz_offset

Returns:

  • (Object)

    the current value of tz_offset



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def tz_offset
  @tz_offset
end

#user_idObject (readonly)

Returns the value of attribute user_id

Returns:

  • (Object)

    the current value of user_id



11
12
13
# File 'lib/slk/models/profile.rb', line 11

def user_id
  @user_id
end

Instance Method Details

#best_nameObject



27
28
29
30
31
32
# File 'lib/slk/models/profile.rb', line 27

def best_name
  return display_name unless display_name.to_s.empty?
  return real_name unless real_name.to_s.empty?

  user_id
end

#external?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/slk/models/profile.rb', line 34

def external?
  is_external
end

#fields_in_section(section_id) ⇒ Object



50
51
52
# File 'lib/slk/models/profile.rb', line 50

def fields_in_section(section_id)
  visible_fields.select { |f| f.section_id == section_id }
end

#people_fieldsObject



46
47
48
# File 'lib/slk/models/profile.rb', line 46

def people_fields
  visible_fields.select { |f| f.type == 'user' }
end

#presence_labelObject



20
21
22
23
24
25
# File 'lib/slk/models/profile.rb', line 20

def presence_label
  case presence
  when 'active' then 'Active'
  when 'away' then 'Away'
  end
end

#reports_fieldObject



66
67
68
# File 'lib/slk/models/profile.rb', line 66

def reports_field
  custom_fields.find { |f| f.type == 'user' && f.inverse }
end

#section(section_id) ⇒ Object



54
55
56
# File 'lib/slk/models/profile.rb', line 54

def section(section_id)
  sections.find { |s| s['id'] == section_id }
end

#supervisor_idsObject

User IDs from the first non-inverse Supervisor-like field. Prefers a field literally labeled “Supervisor”.



60
61
62
63
64
# File 'lib/slk/models/profile.rb', line 60

def supervisor_ids
  preferred = people_fields.find { |f| f.label.to_s.casecmp('Supervisor').zero? && !f.inverse }
  preferred ||= people_fields.find { |f| !f.inverse }
  preferred ? preferred.user_ids : []
end

#visible_fieldsObject

Custom fields with values, ordered by ordering then label. Hidden fields are filtered unless explicitly requested.



40
41
42
43
44
# File 'lib/slk/models/profile.rb', line 40

def visible_fields
  custom_fields
    .reject { |f| f.empty? || f.hidden }
    .sort_by { |f| [f.ordering.to_i, f.label.to_s] }
end