Class: Twterm::UserWindow

Inherits:
Object
  • Object
show all
Includes:
Curses, Singleton
Defined in:
lib/twterm/user_window.rb

Instance Method Summary collapse

Constructor Details

#initializeUserWindow

Returns a new instance of UserWindow.



6
7
8
# File 'lib/twterm/user_window.rb', line 6

def initialize
  @window = stdscr.subwin(stdscr.maxy - 2, 30, 0, stdscr.maxx - 30)
end

Instance Method Details

#refresh_windowObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/twterm/user_window.rb', line 17

def refresh_window
  @window.clear

  if @user.nil?
    draw_border
    @window.refresh
    return
  end

  @window.bold do
    @window.setpos(1, 2)
    @window.addstr(@user.name)
    @window.setpos(2, 2)
    @window.addstr("@#{@user.screen_name}")
  end

  @window.setpos(4, 2)
  @window.addstr("#{@user.statuses_count.format} tweets  ".rjust(@window.maxx - 2))
  @window.setpos(5, 2)
  @window.addstr("#{@user.friends_count.format} following  ".rjust(@window.maxx - 2))
  @window.setpos(6, 2)
  @window.addstr("#{@user.followers_count.format} followers  ".rjust(@window.maxx - 2))

  @window.setpos(8, 2)
  @window.addstr('Location:')
  @window.setpos(9, 4)
  @window.addstr(@user.location)

  @window.setpos(10, 2)
  @window.addstr('Website:')
  @window.setpos(11, 4)
  @window.addstr(@user.website)

  @user.description.split_by_width(@window.maxx - 4).each.with_index(0) do |line, i|
    @window.setpos(13 + i, 2)
    @window.addstr(line)
  end

  draw_border

  @window.refresh
end

#update(user) ⇒ Object



10
11
12
13
14
15
# File 'lib/twterm/user_window.rb', line 10

def update(user)
  fail ArgumentError, 'argument must be an instance of User class' unless user.is_a? User

  @user = user
  refresh_window
end