Class: Tweetskim::Formatter
- Inherits:
-
Object
- Object
- Tweetskim::Formatter
- Defined in:
- lib/tweetskim/formatter.rb
Instance Method Summary collapse
- #html(tweets, options = {}) ⇒ Object
- #htmlize(tweet) ⇒ Object
- #lines(tweets, options = {}) ⇒ Object
- #text(tweet) ⇒ Object
- #time(tweet) ⇒ Object
Instance Method Details
#html(tweets, options = {}) ⇒ Object
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 83 84 |
# File 'lib/tweetskim/formatter.rb', line 37 def html(tweets, = {}) 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 24 25 |
# 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>" # TODO a ref for links text = text.gsub(/http/, '**\1**') end |
#lines(tweets, options = {}) ⇒ Object
7 8 9 10 |
# File 'lib/tweetskim/formatter.rb', line 7 def lines(tweets, = {}) 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
27 28 29 30 31 32 33 34 35 |
# File 'lib/tweetskim/formatter.rb', line 27 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 |