Class: Twitter::Tweet

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_filter/tweet.rb

Instance Method Summary collapse

Instance Method Details

#display(format = "string") ⇒ Object



26
27
28
# File 'lib/twitter_filter/tweet.rb', line 26

def display(format="string")
  puts self.send("display_" + format)
end

#display_stringObject



30
31
32
33
34
35
36
37
38
# File 'lib/twitter_filter/tweet.rb', line 30

def display_string
  'User: ' + user.screen_name + "\n" +
  'User img: ' + user.profile_image_url + "\n" +
  'Text: ' + full_text + "\n" +
  "from " + source + "\n" +
  created_at.to_s + "\n" +
  display_time_ago + "\n" +
  "#{user.screen_name} [#{created_at.to_s}]: #{text}"
end

#display_time_agoObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twitter_filter/tweet.rb', line 9

def display_time_ago
  seconds_ago = Time.now - created_at
  if seconds_ago < 60
    return "less than a minute ago"
  elsif seconds_ago < 60*2
    return "about a minute ago"
  elsif seconds_ago < 60*60
    return "about #{(seconds_ago/60).round} minutes ago"
  elsif seconds_ago < 60*60*2
    return "about an hour ago"
  elsif seconds_ago < 60*60*24
    return "about #{(seconds_ago/(60*60)).round} hours ago"
  else
    return "about #{(seconds_ago/(60*60*24)).round} days ago"
  end
end

#to_hashObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/twitter_filter/tweet.rb', line 40

def to_hash
  tweet_hash =
    {"full_text" => full_text,
     "text" => text,
     "source" => source,
     "created_at" => created_at.to_s,
     "display_time_ago" => display_time_ago,
     "user" => {"screen_name" => user.screen_name, "profile_image_url" => user.profile_image_url}}
  tweet_hash["in_reply_to_screen_name"] = in_reply_to_screen_name if in_reply_to_screen_name
  tweet_hash
end

#to_jsonObject



52
53
54
# File 'lib/twitter_filter/tweet.rb', line 52

def to_json
  to_hash.to_json
end