stars 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.4.0
data/lib/stars/favstar.rb DELETED
@@ -1,33 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'nokogiri'
4
- module Stars
5
- class Favstar
6
- include HTTParty
7
- base_uri 'favstar.fm'
8
- proxy_url = URI.parse(ENV['http_proxy']) if ENV['http_proxy']
9
- http_proxy proxy_url.host,proxy_url.port if proxy_url
10
-
11
- def recent(username)
12
- self.class.get("/users/#{username}/rss",
13
- :format => :xml)['rss']['channel']['item']
14
- end
15
-
16
- def show(url)
17
- # hardcode 17 to strip favstar domain for now
18
- html = self.class.get(url[17..200], :format => :html)
19
-
20
- output = ''
21
-
22
- Nokogiri::HTML(html).css('div[id^="faved_by_others"] img').collect do |img|
23
- output << " ★ #{img.attributes['alt'].value}\n"
24
- end
25
-
26
- Nokogiri::HTML(html).css('div[id^="rt_by_others"] img').collect do |img|
27
- output << " RT #{img.attributes['alt'].value}\n"
28
- end
29
-
30
- output
31
- end
32
- end
33
- end
@@ -1,70 +0,0 @@
1
- require 'terminal-table/import'
2
-
3
- module Stars
4
- class Formatter
5
-
6
- attr_accessor :tweets
7
-
8
- def initialize(tweets)
9
- @tweets = tweets
10
- end
11
-
12
- # I hate clients that don't retain line breaks, but in this case I'm boss.
13
- def trim(text)
14
- truncated = text.gsub("\n"," ")[0..50]
15
- truncated + (truncated.size == text.size ? '' : '...')
16
- end
17
-
18
- def format(i, tweet)
19
- stars,text = split_stars(tweet['title'])
20
- [i,stars,relative_time(tweet['pubDate']),text]
21
- end
22
-
23
- def split_stars(text)
24
- stars = text.match(/[\d+]./)[0].to_i
25
- strip_point = text.index(':') + 2
26
- text = text[strip_point..text.size]
27
- [characterize(stars),trim(text)]
28
- end
29
-
30
- def characterize(number)
31
- if number > 5
32
- "* x #{number}"
33
- else
34
- (1..number).collect{'*'}.join(' ')
35
- end
36
- end
37
-
38
- def line_break
39
- "\n"
40
- end
41
-
42
- def to_s
43
- tweets = @tweets.collect_with_index{|tweet,i| format(i+1,tweet)}
44
- table(['#','Stars','Time','Your Funnies'], *tweets).render
45
- end
46
-
47
- def relative_time(time)
48
- post_date = Time.parse(time)
49
- timespan = Time.now - Time.parse(time)
50
-
51
- case timespan
52
- when 0..59
53
- "just now"
54
- when 60..(3600-1)
55
- "#{pluralize((timespan/60).to_i, 'minute', 'minutes')} ago"
56
- when 3600..(3600*24-1)
57
- "#{pluralize((timespan/3600).to_i, 'hour', 'hours')} ago"
58
- when (3600*24)..(3600*24*30)
59
- "#{pluralize((timespan/(3600*24)).to_i, 'day', 'days')} ago"
60
- else
61
- post_date.strftime("%m/%d/%Y")
62
- end
63
- end
64
-
65
- # ActiveSupport pluralize
66
- def pluralize(count, singular, plural = nil)
67
- "#{count || 0} " + ((count == 1 || count == '1') ? singular : (plural || singular.pluralize))
68
- end
69
- end
70
- end
@@ -1,66 +0,0 @@
1
- require 'helper'
2
-
3
- class TestFormatter < Test::Unit::TestCase
4
-
5
- def setup
6
- @formatter = Stars::Formatter.new(favstar_tweet_hash)
7
- end
8
-
9
- def test_trim_breaks
10
- tweet = "Line breaks\nare for lovers"
11
- assert_equal @formatter.trim(tweet), 'Line breaks are for lovers'
12
- end
13
-
14
- def test_trim_length
15
- tweet = "This is a tweet that is long enough to certainly "+
16
- "need at least SOME truncating lol lol sigh."
17
- assert_equal @formatter.trim(tweet),
18
- 'This is a tweet that is long enough to certainly ne...'
19
- end
20
-
21
- def test_format
22
- format = @formatter.format(1,favstar_tweet_hash[0])
23
- assert_equal format.size, 4
24
- assert_equal 1,format[0], '* *'
25
- end
26
-
27
- def test_split_stars
28
- tweet = "12 stars: A short tweet. Hey, a number: 5."
29
- assert_equal @formatter.split_stars(tweet),
30
- ['* x 12', 'A short tweet. Hey, a number: 5.']
31
- end
32
-
33
- def test_characterize_with_lots_of_stars
34
- assert_equal @formatter.characterize(12),
35
- '* x 12'
36
- end
37
-
38
- def test_characterize_with_a_few_stars
39
- assert_equal @formatter.characterize(4),
40
- '* * * *'
41
- end
42
-
43
- def test_line_break
44
- assert_equal @formatter.line_break, "\n"
45
- end
46
-
47
- def test_to_s
48
- # just make sure it doesn't blow up for now
49
- @formatter.to_s
50
- end
51
-
52
- def test_relative_time
53
- assert_equal @formatter.relative_time((Time.now - 2).to_s),
54
- "just now"
55
- assert_equal @formatter.relative_time((Time.now - 360).to_s),
56
- "6 minutes ago"
57
- assert_equal @formatter.relative_time((Time.now - 10000).to_s),
58
- "2 hours ago"
59
- end
60
-
61
- def test_pluralizer
62
- assert_equal @formatter.pluralize(1, 'day', 'day'), '1 day'
63
- assert_equal @formatter.pluralize(2, 'day', 'days'), '2 days'
64
- end
65
-
66
- end
data/test/test_stars.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'helper'
2
-
3
- class TestStars < Test::Unit::TestCase
4
-
5
- def test_model
6
- assert defined?(Stars)
7
- end
8
-
9
- end