Class: Slk::Formatters::ProfileRows

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/formatters/profile_rows.rb

Overview

Builds [label, value] row pairs from a Models::Profile. Pure data — no output, formatting handled by ProfileFormatter.

Instance Method Summary collapse

Constructor Details

#initialize(field_renderer:, emoji_replacer: nil) ⇒ ProfileRows

Returns a new instance of ProfileRows.



8
9
10
11
# File 'lib/slk/formatters/profile_rows.rb', line 8

def initialize(field_renderer:, emoji_replacer: nil)
  @fields = field_renderer
  @emoji_replacer = emoji_replacer
end

Instance Method Details

#about(profile, skip_title: false) ⇒ Object



35
36
37
38
39
# File 'lib/slk/formatters/profile_rows.rb', line 35

def about(profile, skip_title: false)
  fields = profile.visible_fields.reject { |f| f.type == 'user' }
  fields = fields.reject { |f| skip_title && duplicate_title?(f, profile) }
  fields.map { |f| [f.label, @fields.render(f, profile)] }
end

#base(profile) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/slk/formatters/profile_rows.rb', line 21

def base(profile)
  [
    ['Presence', profile.presence_label],
    ['Status', status_text(profile)],
    ['Local', local_time(profile)]
  ]
end

#compact(profile) ⇒ Object



13
14
15
# File 'lib/slk/formatters/profile_rows.rb', line 13

def compact(profile)
  contact(profile) + base(profile) + people(profile) + about(profile, skip_title: true)
end

#contact(profile) ⇒ Object



17
18
19
# File 'lib/slk/formatters/profile_rows.rb', line 17

def contact(profile)
  [['Email', profile.email], ['Phone', profile.phone]]
end

#external(profile) ⇒ Object



41
42
43
# File 'lib/slk/formatters/profile_rows.rb', line 41

def external(profile)
  contact(profile) + [['Workspace', profile.home_team_name]]
end

#people(profile) ⇒ Object



29
30
31
32
33
# File 'lib/slk/formatters/profile_rows.rb', line 29

def people(profile)
  profile.people_fields.flat_map do |field|
    field.user_ids.map { |uid| [field.label, @fields.render_user_reference(uid, profile)] }
  end
end