Class: Twterm::Tab::Statuses::Favorites

Inherits:
Base
  • Object
show all
Includes:
Dumpable
Defined in:
lib/twterm/tab/statuses/favorites.rb

Instance Attribute Summary collapse

Attributes included from Twterm::Tab::Scrollable

#scroller

Attributes inherited from Base

#window

Instance Method Summary collapse

Methods included from Dumpable

included

Methods inherited from Base

#append, #delete, #destroy_status, #drawable_item_count, #favorite, #items, #open_link, #prepend, #reply, #respond_to_key, #retweet, #show_conversation, #show_user, #statuses, #total_item_count, #touch_statuses, #update

Methods included from Utils

check_type

Methods included from Subscriber

included, #subscribe, #unsubscribe

Methods included from Twterm::Tab::Scrollable

#total_item_count

Methods included from Publisher

#publish

Methods included from FilterableList

#filter, #filter_query, #items, #reset_filter

Methods inherited from Base

#close, #refresh, #respond_to_key

Constructor Details

#initialize(user_id) ⇒ Favorites

Returns a new instance of Favorites.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/twterm/tab/statuses/favorites.rb', line 27

def initialize(user_id)
  super()

  @user_id = user_id

  User.find_or_fetch(user_id).then do |user|
    @user = user
    TabManager.instance.refresh_window

    fetch { scroller.move_to_top }
  end
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



9
10
11
# File 'lib/twterm/tab/statuses/favorites.rb', line 9

def user
  @user
end

#user_idObject (readonly)

Returns the value of attribute user_id.



9
10
11
# File 'lib/twterm/tab/statuses/favorites.rb', line 9

def user_id
  @user_id
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
# File 'lib/twterm/tab/statuses/favorites.rb', line 11

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

#dumpObject



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

def dump
  @user.id
end

#fetchObject



19
20
21
22
23
24
25
# File 'lib/twterm/tab/statuses/favorites.rb', line 19

def fetch
  Client.current.favorites(@user.id).then do |statuses|
    statuses.reverse.each(&method(:prepend))
    sort
    yield if block_given?
  end
end

#titleObject



40
41
42
# File 'lib/twterm/tab/statuses/favorites.rb', line 40

def title
  @user.nil? ? 'Loading...' : "@#{@user.screen_name} likes"
end