sarnesjo-twhere 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,5 +18,5 @@ end
18
18
 
19
19
  require 'spec/rake/spectask'
20
20
  Spec::Rake::SpecTask.new do |spec|
21
- spec.spec_files = %w{spec/hashtag_spec.rb spec/twhere_spec.rb}
21
+ spec.spec_files = %w{spec/hashtags_spec.rb spec/twhere_spec.rb}
22
22
  end
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 11
3
+ :patch: 12
4
4
  :major: 0
@@ -3,8 +3,8 @@ require 'erb'
3
3
  require 'twitter'
4
4
 
5
5
  module TwhereHelperMethods
6
- def hashtag(str)
7
- md = str.match(/#([A-Za-z0-9]+)/) and md[1]
6
+ def hashtags(str)
7
+ str.scan(/#([A-Za-z0-9]+)/).flatten.uniq
8
8
  end
9
9
  end
10
10
 
@@ -34,8 +34,8 @@ class Twhere
34
34
  # group tweets by location
35
35
  @located_tweets = {}
36
36
  @tweets.each do |t|
37
- ht = hashtag(t[:text])
38
- if ht and @locations.keys.include? ht
37
+ located_hashtags = hashtags(t[:text]) & @locations.keys
38
+ located_hashtags.each do |ht|
39
39
  @located_tweets[ht] ||= []
40
40
  @located_tweets[ht] << t
41
41
  end
@@ -0,0 +1,60 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'spec_helper'
3
+
4
+ describe 'hashtags method' do
5
+ include TwhereHelperMethods
6
+
7
+ it 'should return empty array when there are no hashtags' do
8
+ hashtags('').should == []
9
+ hashtags('a').should == []
10
+ hashtags('#').should == []
11
+ hashtags('##').should == []
12
+ end
13
+
14
+ it 'should find hashtags containing only lowercase letters' do
15
+ hashtags('#a').should == ['a']
16
+ hashtags('#aa').should == ['aa']
17
+ end
18
+
19
+ it 'should find hashtags containing only uppercase letters' do
20
+ hashtags('#A').should == ['A']
21
+ hashtags('#AA').should == ['AA']
22
+ end
23
+
24
+ it 'should find hashtags containing only digits' do
25
+ hashtags('#1').should == ['1']
26
+ hashtags('#11').should == ['11']
27
+ end
28
+
29
+ it 'should find hashtags containing mixed character classes' do
30
+ hashtags('#aA').should == ['aA']
31
+ hashtags('#Aa').should == ['Aa']
32
+ hashtags('#a1').should == ['a1']
33
+ hashtags('#1a').should == ['1a']
34
+ hashtags('#A1').should == ['A1']
35
+ hashtags('#1A').should == ['1A']
36
+ end
37
+
38
+ it 'should find hashtags in text' do
39
+ hashtags('a #b').should == ['b']
40
+ hashtags('#a b').should == ['a']
41
+ end
42
+
43
+ it 'should return all hashtags found' do
44
+ hashtags('#a #b').should == ['a', 'b']
45
+ end
46
+
47
+ it 'should only return each hashtag once' do
48
+ hashtags('#a #a').should == ['a']
49
+ hashtags('#a #a #b').should == ['a', 'b']
50
+ end
51
+
52
+ it 'should not include punctuation in hashtags' do
53
+ hashtags('#a.').should == ['a']
54
+ hashtags('#a,').should == ['a']
55
+ hashtags('#a:').should == ['a']
56
+ hashtags('#a;').should == ['a']
57
+ hashtags('#a!').should == ['a']
58
+ hashtags('#a?').should == ['a']
59
+ end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sarnesjo-twhere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jesper S\xC3\xA4rnesj\xC3\xB6"
@@ -68,6 +68,6 @@ signing_key:
68
68
  specification_version: 3
69
69
  summary: Twitter/Google Maps mashup
70
70
  test_files:
71
- - spec/hashtag_spec.rb
71
+ - spec/hashtags_spec.rb
72
72
  - spec/spec_helper.rb
73
73
  - spec/twhere_spec.rb
@@ -1,55 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__))
2
- require 'spec_helper'
3
-
4
- describe 'hashtag method' do
5
- include TwhereHelperMethods
6
-
7
- it 'should return nil when there are no hashtags' do
8
- hashtag('').should == nil
9
- hashtag('a').should == nil
10
- hashtag('#').should == nil
11
- hashtag('##').should == nil
12
- end
13
-
14
- it 'should find hashtags containing only lowercase letters' do
15
- hashtag('#a').should == 'a'
16
- hashtag('#aa').should == 'aa'
17
- end
18
-
19
- it 'should find hashtags containing only uppercase letters' do
20
- hashtag('#A').should == 'A'
21
- hashtag('#AA').should == 'AA'
22
- end
23
-
24
- it 'should find hashtags containing only digits' do
25
- hashtag('#1').should == '1'
26
- hashtag('#11').should == '11'
27
- end
28
-
29
- it 'should find hashtags containing mixed character classes' do
30
- hashtag('#aA').should == 'aA'
31
- hashtag('#Aa').should == 'Aa'
32
- hashtag('#a1').should == 'a1'
33
- hashtag('#1a').should == '1a'
34
- hashtag('#A1').should == 'A1'
35
- hashtag('#1A').should == '1A'
36
- end
37
-
38
- it 'should find hashtags in text' do
39
- hashtag('a #b').should == 'b'
40
- hashtag('#a b').should == 'a'
41
- end
42
-
43
- it 'should return the first hashtag found' do
44
- hashtag('#a #b').should == 'a'
45
- end
46
-
47
- it 'should not include punctuation in hashtags' do
48
- hashtag('#a.').should == 'a'
49
- hashtag('#a,').should == 'a'
50
- hashtag('#a:').should == 'a'
51
- hashtag('#a;').should == 'a'
52
- hashtag('#a!').should == 'a'
53
- hashtag('#a?').should == 'a'
54
- end
55
- end