Class: Tweetskim::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/tweetskim/formatter.rb

Instance Method Summary collapse

Instance Method Details

#html(tweets, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tweetskim/formatter.rb', line 35

def html(tweets, options = {})
  html_tweets = tweets.reverse.map {|tweet| htmlize(tweet)}.join("")

  body = <<HTML
<!DOCTYPE html>
<html lang="en">
  <head>
<meta charset="utf-8">
<title>Tweetskim</title>
  </head>
  <body>
<style>
  #tweets {
    width: 500px;
    margin-left: 50px;
  }

  .tweet {
     margin-top: 50px;
     margin-bottom: 50px;
  }

  .tweet h1 {
    color: #ADADAD;
    font-size: 2.0em;
    margin-bottom: 0px;
  }

  .tweet .time {
    color: #ADADAD;
    font-size: 0.5em;
  }

  .tweet p {
    font-size: 1.2em;
    margin: 0 0 0 0;
    margin-left: 50px;
    font-family: sans-serif;
  }
</style>
<div id="tweets">
  #{html_tweets}
</div>
  </body>
</html>
HTML
  return body
end

#htmlize(tweet) ⇒ Object



20
21
22
23
# File 'lib/tweetskim/formatter.rb', line 20

def htmlize(tweet)
  text = text(tweet).gsub('\n', '<br/>')
  "<div class='tweet'><h1>#{tweet.user.name} <span class='time'>#{time(tweet)}</span></h1><p>#{text}<p></div>"
end

#lines(tweets, options = {}) ⇒ Object



7
8
9
10
# File 'lib/tweetskim/formatter.rb', line 7

def lines(tweets, options = {})
  tweet_texts = tweets.reverse.map {|tweet| "--#{tweet.user.name}-- #{text(tweet)}\n"}
  lines = tweet_texts.join("")
end

#text(tweet) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/tweetskim/formatter.rb', line 12

def text(tweet)
  if tweet.retweeted_status
    "RT @#{tweet.retweeted_status.user.screen_name}: #{tweet.retweeted_status.text}"
  else
    tweet.text
  end
end

#time(tweet) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/tweetskim/formatter.rb', line 25

def time(tweet)
  tweet_time = tweet.created_at
  now = Time.now
  if now.day != tweet_time.day
    "#{tweet_time.day} / #{tweet_time.mon}"
  else
    "#{tweet_time.hour}:#{tweet_time.min}"
  end
end