twalk 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +7 -15
- data/Rakefile +7 -0
- data/lib/twalk.rb +29 -1
- data/lib/twalk/version.rb +1 -1
- data/spec/twalk_spec.rb +53 -0
- data/twalk.gemspec +0 -2
- metadata +6 -20
data/README.md
CHANGED
@@ -6,30 +6,22 @@ The idea is that in some situations you may only want a [Twitter](http://twitter
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Although you can get nicknames and tweets as you please, I've used the following:
|
10
10
|
|
11
|
+
gem 'twitter # To get tweets
|
11
12
|
gem 'twalk'
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install twalk
|
13
|
+
gem 'twitter-text' # To format tweets
|
20
14
|
|
21
15
|
## Usage
|
22
16
|
|
23
17
|
```ruby
|
18
|
+
nicknames = %w(_gareth cardiffrb)
|
19
|
+
tweets = Twitter.home_timeline.collect { |tweet| tweet.text }
|
24
20
|
|
25
|
-
|
26
|
-
users = User.all.collect { |user| user.nickname }
|
27
|
-
users = %w(_gareth cardiffrb)
|
28
|
-
|
29
|
-
@tweets = Twalk::Twalk.tweets_between(users)
|
21
|
+
@twalks = Twalk.tweets_between(nicknames, tweets)
|
30
22
|
|
31
23
|
# your_view.html.erb
|
32
|
-
@
|
24
|
+
@twalks.each do |tweet|
|
33
25
|
<div class="tweet">auto_link tweet.text</div>
|
34
26
|
end
|
35
27
|
```
|
data/Rakefile
CHANGED
data/lib/twalk.rb
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
require "twalk/version"
|
2
2
|
|
3
3
|
module Twalk
|
4
|
-
|
4
|
+
|
5
|
+
class << self
|
6
|
+
# Public: Return an Array of Strings where nicknames mention each other
|
7
|
+
#
|
8
|
+
# nicknames - the Array of String twitter nicknames to be scanned
|
9
|
+
# tweets - the Array of Strings to be scanned
|
10
|
+
#
|
11
|
+
# Examples
|
12
|
+
#
|
13
|
+
# nicknames = %w(_gareth cardiffrb)
|
14
|
+
# tweets = Twitter.home_timeline.collect { |tweet| tweet.text }
|
15
|
+
#
|
16
|
+
# tweets_between(nicknames, tweets)
|
17
|
+
# # ...some processing...
|
18
|
+
# # => @_gareth: hey @cardiffrb!
|
19
|
+
# # => @cardiffrb: nice to meet you, @_gareth
|
20
|
+
#
|
21
|
+
# Returns an array of Strings
|
22
|
+
def tweets_between(nicknames, tweets)
|
23
|
+
tweets_to_show = []
|
24
|
+
tweets.each do |tweet|
|
25
|
+
nicknames.each do |user|
|
26
|
+
tweets_to_show << tweet if tweet.downcase.include? user
|
27
|
+
end
|
28
|
+
end
|
29
|
+
tweets_to_show.uniq
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
5
33
|
end
|
data/lib/twalk/version.rb
CHANGED
data/spec/twalk_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
|
5
|
+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
6
|
+
require "twalk"
|
7
|
+
|
8
|
+
describe Twalk do
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@nicknames = %w(_gareth cardiffrb)
|
12
|
+
@tweets = ["hello @_gareth", "hi there @cardiffrb", "Tweet to no one", "Hi @_gareth and @cardiffrb"]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return tweets that mention a nickname" do
|
16
|
+
Twalk::tweets_between(["@_gareth"], ["Hey @_gareth"]).size.must_equal 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not return tweets that do not mention a nickname" do
|
20
|
+
Twalk::tweets_between(["@_gareth"], ["Hey @twitter"]).size.must_equal 0
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not return duplicate tweets for tweets that mention several nickname" do
|
24
|
+
Twalk::tweets_between(["@_gareth", "@cardiffrb"], ["Hey @_gareth and @cardiffrb"]).size.must_equal 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not return duplicate tweets for tweets that mention the same nickname more than once" do
|
28
|
+
Twalk::tweets_between(["@_gareth"], ["Hey @_gareth. How are you @_gareth?"]).size.must_equal 1
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return tweets that mention a known and unknown nickname" do
|
32
|
+
Twalk::tweets_between(["@_gareth", "@twitter"], ["Hey @_gareth and @twitter"]).size.must_equal 1
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return multiple tweets that mention a nickname" do
|
36
|
+
Twalk::tweets_between(["@_gareth"], ["Hey @_gareth", "Hello @_gareth"]).size.must_equal 2
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return multiple tweets that mention individual nicknames" do
|
40
|
+
nicknames = ["@_gareth", "@cardiffrb"]
|
41
|
+
tweets = ["Hey @_gareth", "Hello @cardiffrb"]
|
42
|
+
Twalk::tweets_between(nicknames, tweets).size.must_equal 2
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return multiple tweets that mention individual nicknames, but not tweets to no one" do
|
46
|
+
Twalk::tweets_between(["@_gareth"], @tweets).size.must_equal 2
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return mutiple tweets that mention multiple nicknames, but not tweets to no one" do
|
50
|
+
Twalk::tweets_between(@nicknames, @tweets).size.must_equal 3
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/twalk.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twalk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: twitter
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 2.0.0
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2.0.0
|
12
|
+
date: 2012-04-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
30
14
|
description: Twalk displays tweets of your followers who are talking to one another
|
31
15
|
email:
|
32
16
|
- gareth.h.rees@gmail.com
|
@@ -41,6 +25,7 @@ files:
|
|
41
25
|
- Rakefile
|
42
26
|
- lib/twalk.rb
|
43
27
|
- lib/twalk/version.rb
|
28
|
+
- spec/twalk_spec.rb
|
44
29
|
- twalk.gemspec
|
45
30
|
homepage: http://github.com/garethrees/twalk
|
46
31
|
licenses: []
|
@@ -66,4 +51,5 @@ rubygems_version: 1.8.21
|
|
66
51
|
signing_key:
|
67
52
|
specification_version: 3
|
68
53
|
summary: Twalk displays tweets of your followers who are talking to one another
|
69
|
-
test_files:
|
54
|
+
test_files:
|
55
|
+
- spec/twalk_spec.rb
|