Class: Myun2::TwitterShell::Ls

Inherits:
Object
  • Object
show all
Defined in:
lib/myun2/twitter_shell/ls.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, *params) ⇒ Ls

Returns a new instance of Ls.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/myun2/twitter_shell/ls.rb', line 8

def initialize(client, *params)
  @client = client

  if params && params.length > 0
    case
    when params[0] == '-m' || params[0] == 'mention' || params[0] == 'mentions'
      params.shift
      timeline = mentions_timeline(*params)
    when params[0][0] != '-'
      user_name = params.shift
      timeline = user_timeline(user_name, *params)
    end
  end
  timeline ||= home_timeline(*params)

  timeline.each do |t|
    puts format(t, *params)
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/myun2/twitter_shell/ls.rb', line 6

def client
  @client
end

Instance Method Details

#format(tweet, *params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/myun2/twitter_shell/ls.rb', line 40

def format(tweet, *params)
  u = tweet['user']
  user_name = u['name']
  screen_name = u['screen_name']
  text = tweet['text']

  if params && params.length > 0 && params[0][0] == '-' && params[0].include?('l')
    datetime = tweet['created_at']
    "#{datetime} \e[38;5;#{u['id'] % 255}m<#{screen_name}:#{user_name}>\e[0m: #{text}"
  else
    "\e[38;5;#{u['id'] % 255}m<#{user_name}>\e[0m: #{text[0..30]}"
  end
end

#home_timeline(*params) ⇒ Object



36
37
38
# File 'lib/myun2/twitter_shell/ls.rb', line 36

def home_timeline(*params)
  client.home_timeline(params_to_options *params)
end

#mentions_timeline(*params) ⇒ Object



32
33
34
# File 'lib/myun2/twitter_shell/ls.rb', line 32

def mentions_timeline(*params)
  client.mentions(params_to_options *params)
end

#user_timeline(screen_name, *params) ⇒ Object



28
29
30
# File 'lib/myun2/twitter_shell/ls.rb', line 28

def user_timeline(screen_name, *params)
  client.user_timeline({ screen_name: screen_name }.merge(params_to_options *params))
end