Class: Slk::Models::Channel

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name: nil, is_private: false, is_im: false, is_mpim: false, is_archived: false) ⇒ Channel

rubocop:disable Metrics/ParameterLists



18
19
20
21
22
23
24
25
26
27
# File 'lib/slk/models/channel.rb', line 18

def initialize(id:, name: nil, is_private: false, is_im: false, is_mpim: false, is_archived: false)
  super(
    id: id.to_s.freeze,
    name: name&.freeze,
    is_private: is_private,
    is_im: is_im,
    is_mpim: is_mpim,
    is_archived: is_archived
  )
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



5
6
7
# File 'lib/slk/models/channel.rb', line 5

def id
  @id
end

#is_archivedObject (readonly)

Returns the value of attribute is_archived

Returns:

  • (Object)

    the current value of is_archived



5
6
7
# File 'lib/slk/models/channel.rb', line 5

def is_archived
  @is_archived
end

#is_imObject (readonly)

Returns the value of attribute is_im

Returns:

  • (Object)

    the current value of is_im



5
6
7
# File 'lib/slk/models/channel.rb', line 5

def is_im
  @is_im
end

#is_mpimObject (readonly)

Returns the value of attribute is_mpim

Returns:

  • (Object)

    the current value of is_mpim



5
6
7
# File 'lib/slk/models/channel.rb', line 5

def is_mpim
  @is_mpim
end

#is_privateObject (readonly)

Returns the value of attribute is_private

Returns:

  • (Object)

    the current value of is_private



5
6
7
# File 'lib/slk/models/channel.rb', line 5

def is_private
  @is_private
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/slk/models/channel.rb', line 5

def name
  @name
end

Class Method Details

.from_api(data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/slk/models/channel.rb', line 6

def self.from_api(data)
  new(
    id: data['id'],
    name: data['name'] || data['name_normalized'],
    is_private: data['is_private'] || false,
    is_im: data['is_im'] || false,
    is_mpim: data['is_mpim'] || false,
    is_archived: data['is_archived'] || false
  )
end

Instance Method Details

#display_nameObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/slk/models/channel.rb', line 38

def display_name
  return name if name

  case id[0]
  when 'C' then '#channel'
  when 'G' then '#private'
  when 'D' then 'DM'
  else id
  end
end

#dm?Boolean

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


30
31
32
# File 'lib/slk/models/channel.rb', line 30

def dm?
  is_im || is_mpim
end

#public?Boolean

Returns:

  • (Boolean)


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

def public?
  !is_private && !dm?
end

#to_sObject



49
50
51
# File 'lib/slk/models/channel.rb', line 49

def to_s
  dm? ? display_name : "##{name || id}"
end