Class: Myun2::TwitterShell::Ls
- Inherits:
-
Object
- Object
- Myun2::TwitterShell::Ls
- Defined in:
- lib/myun2/twitter_shell/ls.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #format(tweet, *params) ⇒ Object
- #home_timeline ⇒ Object
-
#initialize(client, *params) ⇒ Ls
constructor
A new instance of Ls.
- #mentions_timeline ⇒ Object
- #user_timeline(screen_name) ⇒ Object
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' timeline = mentions_timeline params.shift when params[0][0] != '-' timeline = user_timeline(params[0]) params.shift end end timeline ||= home_timeline timeline.each do |t| puts format(t, *params) end end |
Instance Attribute Details
#client ⇒ Object (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} <#{screen_name}:#{user_name}>: #{text}" else "<#{user_name}>: #{text[0..30]}" end end |
#home_timeline ⇒ Object
36 37 38 |
# File 'lib/myun2/twitter_shell/ls.rb', line 36 def home_timeline client.home_timeline end |
#mentions_timeline ⇒ Object
32 33 34 |
# File 'lib/myun2/twitter_shell/ls.rb', line 32 def mentions_timeline client.mentions end |
#user_timeline(screen_name) ⇒ Object
28 29 30 |
# File 'lib/myun2/twitter_shell/ls.rb', line 28 def user_timeline(screen_name) client.user_timeline(screen_name: screen_name) end |