Class: Hobostove::UserPanel

Inherits:
Panel
  • Object
show all
Defined in:
lib/hobostove/user_panel.rb

Instance Attribute Summary

Attributes inherited from Panel

#height, #options, #startx, #starty, #width

Instance Method Summary collapse

Methods inherited from Panel

#<<, #refresh!, #scroll_down, #scroll_up, #wrap_lines?

Constructor Details

#initialize(*args) ⇒ UserPanel

Returns a new instance of UserPanel.



3
4
5
6
7
# File 'lib/hobostove/user_panel.rb', line 3

def initialize(*args)
  super

  @users = Set.new
end

Instance Method Details

#add_user(user, do_refresh = true) ⇒ Object



13
14
15
16
17
# File 'lib/hobostove/user_panel.rb', line 13

def add_user(user, do_refresh = true)
  @users.add(user)

  refresh if do_refresh
end

#refreshObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/hobostove/user_panel.rb', line 25

def refresh
  @strings = @users.map do |user|
    Line.new.tap do |line|
      line.add(:cyan, user.name)
    end
  end
  @strings.sort!

  super
end

#remove_user(user, do_refresh = true) ⇒ Object



19
20
21
22
23
# File 'lib/hobostove/user_panel.rb', line 19

def remove_user(user, do_refresh = true)
  @users.delete(user)

  refresh if do_refresh
end

#user_namesObject



9
10
11
# File 'lib/hobostove/user_panel.rb', line 9

def user_names
  @users.map(&:name)
end