Class: Twterm::Tab::UserTab

Inherits:
Base
  • Object
show all
Includes:
Publisher, Dumpable, Scrollable
Defined in:
lib/twterm/tab/user_tab.rb

Instance Attribute Summary collapse

Attributes included from Scrollable

#scroller

Attributes inherited from Base

#title, #window

Instance Method Summary collapse

Methods included from Scrollable

#total_item_count

Methods included from Publisher

#publish

Methods included from Utils

check_type

Methods included from Dumpable

included

Methods inherited from Base

#close, #refresh

Methods included from Subscriber

included, #subscribe, #unsubscribe

Constructor Details

#initialize(user_id) ⇒ UserTab

Returns a new instance of UserTab.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/twterm/tab/user_tab.rb', line 30

def initialize(user_id)
  super()

  self.title = 'Loading...'.freeze
  @user_id = user_id

  User.find_or_fetch(user_id).then do |user|
    refresh

    Client.current.lookup_friendships
    self.title = "@#{user.screen_name}"
  end
end

Instance Attribute Details

#user_idObject (readonly)

Returns the value of attribute user_id.



12
13
14
# File 'lib/twterm/tab/user_tab.rb', line 12

def user_id
  @user_id
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
# File 'lib/twterm/tab/user_tab.rb', line 14

def ==(other)
  other.is_a?(self.class) && user_id == other.user_id
end

#drawable_item_countObject



22
23
24
# File 'lib/twterm/tab/user_tab.rb', line 22

def drawable_item_count
  (window.maxy - 11 - bio_height).div(2)
end

#dumpObject



18
19
20
# File 'lib/twterm/tab/user_tab.rb', line 18

def dump
  user_id
end

#fetchObject



26
27
28
# File 'lib/twterm/tab/user_tab.rb', line 26

def fetch
  update
end

#itemsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/twterm/tab/user_tab.rb', line 44

def items
  items = %i(
    open_timeline_tab
    show_friends
    show_followers
    show_likes
  )
  items << :compose_direct_message unless myself?
  items << :open_website  unless user.website.nil?
  items << :toggle_follow unless myself?
  items << :toggle_mute   unless myself?
  items << :toggle_block  unless myself?

  items
end

#respond_to_key(key) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/twterm/tab/user_tab.rb', line 60

def respond_to_key(key)
  return true if scroller.respond_to_key(key)

  case key
  when ?D
    compose_direct_message unless myself?
  when ?F
    follow unless myself?
  when 10
    perform_selected_action
  when ?t
    open_timeline_tab
  when ?W
    open_website
  else
    return false
  end

  true
end