Class: Twterm::Tab::UserTab

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

Instance Attribute Summary collapse

Attributes inherited from AbstractTab

#title

Instance Method Summary collapse

Methods included from Scrollable

#scroller, #total_item_count

Methods included from Publisher

#publish

Methods included from Utils

check_type

Methods included from Dumpable

included

Methods inherited from AbstractTab

#close, #find_or_fetch_list, #find_or_fetch_status, #find_or_fetch_user, #render

Methods included from Subscriber

included, #subscribe, #unsubscribe

Constructor Details

#initialize(app, client, user_id) ⇒ UserTab

Returns a new instance of UserTab.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/twterm/tab/user_tab.rb', line 33

def initialize(app, client, user_id)
  super(app, client)

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

  find_or_fetch_user(user_id).then do |user|
    render

    client.lookup_friendships.then { render } unless app.friendship_repository.already_looked_up?(user_id)
    self.title = "@#{user.screen_name}"
  end
end

Instance Attribute Details

#user_idObject (readonly)

Returns the value of attribute user_id.



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

def user_id
  @user_id
end

Instance Method Details

#==(other) ⇒ Object



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

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

#drawable_item_countObject



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

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

#dumpObject



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

def dump
  user_id
end

#fetchObject



29
30
31
# File 'lib/twterm/tab/user_tab.rb', line 29

def fetch
  render
end

#itemsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/twterm/tab/user_tab.rb', line 47

def items
  items = [
    :open_timeline_tab,
    :show_friends,
    :show_followers,
    :show_likes,
    :profile_image,
    (:profile_background_image unless user.profile_background_image.nil?),
    :manage_lists,
    (:open_website unless user.website.nil?),
    (:toggle_follow unless myself?),
    (:toggle_mute unless myself?),
    (:toggle_block unless myself?),
    :open_in_browser,
  ].compact

  items
end

#respond_to_key(key) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/twterm/tab/user_tab.rb', line 66

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

  case key
  when 10
    perform_selected_action
  else
    return false
  end

  true
end