replacer_bot 0.1.1.pre.rc1 → 0.1.1.pre.rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/replacer_bot/helpers.rb +12 -15
- data/lib/replacer_bot/version.rb +1 -1
- data/spec/lib/replacer_bot/advanced_search_spec.rb +15 -6
- data/spec/lib/replacer_bot/helpers_spec.rb +0 -7
- data/spec/vcr/ReplacerBot_Replacer/advanced_search/finds_the_correct_tweets.yml +1237 -1242
- data/spec/vcr/ReplacerBot_Replacer/advanced_search/finds_tweets.yml +1295 -2718
- data/spec/vcr/ReplacerBot_Replacer/advanced_search/searches_for_tweets.yml +1237 -1242
- metadata +1 -3
- data/spec/vcr/ReplacerBot_Replacer/advanced_search/finds_English_tweets.yml +0 -1364
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3826a9d118356a0f052648585a26e6a0583b570a
|
|
4
|
+
data.tar.gz: badfd138905d15a4ca6dc52d8c11d0ff04207c61
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72c4e941085e4ecf3406ab028584b999683e9b952f057fccf9cbaf78adfc70ded5e294bb423d5bf2d49ad7f2632517c30cda9d0ed015d7be5c3553b7202bb1fc
|
|
7
|
+
data.tar.gz: a8c07e4495fa7e81c39fe4ee969dd6dc0e9d820ee9c6edc72a1ad846bcda97fdf5baf40ab67a36ba9f7996d87001ed145173595bc218d305718d73c58452598c
|
data/lib/replacer_bot/helpers.rb
CHANGED
|
@@ -13,7 +13,6 @@ end
|
|
|
13
13
|
|
|
14
14
|
module ReplacerBot
|
|
15
15
|
def self.encode term:
|
|
16
|
-
return term if self.complex_search(string: term)
|
|
17
16
|
URI.encode "\"#{term}\""
|
|
18
17
|
end
|
|
19
18
|
|
|
@@ -39,22 +38,10 @@ module ReplacerBot
|
|
|
39
38
|
def self.validate string:, term: Config.instance.config.search_term, ignore_spaces: true
|
|
40
39
|
return false if string[0...2] == 'RT'
|
|
41
40
|
return false if string[0] == '@'
|
|
41
|
+
return false unless self.has_extra_terms(string: string)
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
term = term.gsub ' ', ' ?' if ignore_spaces
|
|
45
|
-
end
|
|
43
|
+
term = term.gsub ' ', ' ?' if ignore_spaces
|
|
46
44
|
return true if string.index(/#{term}/i) && SeenTweets.validate(string)
|
|
47
|
-
return true if self.complex_search(string: term)
|
|
48
|
-
|
|
49
|
-
false
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def self.complex_search string:
|
|
53
|
-
['OR', 'AND'].map do |word|
|
|
54
|
-
if string.index " #{word} "
|
|
55
|
-
return true
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
45
|
|
|
59
46
|
false
|
|
60
47
|
end
|
|
@@ -64,6 +51,16 @@ module ReplacerBot
|
|
|
64
51
|
select { |i| i.id > self.last_tweet}
|
|
65
52
|
end
|
|
66
53
|
|
|
54
|
+
def self.has_extra_terms string:
|
|
55
|
+
return true unless Config.instance.config.extra_search_terms
|
|
56
|
+
|
|
57
|
+
Config.instance.config.extra_search_terms.each do |term|
|
|
58
|
+
return true if string.downcase.index term.downcase
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
false
|
|
62
|
+
end
|
|
63
|
+
|
|
67
64
|
def self.dehash word
|
|
68
65
|
if is_hashtag word
|
|
69
66
|
return word[1..-1]
|
data/lib/replacer_bot/version.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module ReplacerBot
|
|
2
2
|
describe Replacer do
|
|
3
3
|
before :each do
|
|
4
|
-
|
|
5
|
-
Config.instance.config.
|
|
4
|
+
Config.instance.config.search_term = "joe root"
|
|
5
|
+
Config.instance.config.extra_search_terms = [ "ashes", "england" ]
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
after :each do
|
|
@@ -23,12 +23,21 @@ module ReplacerBot
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it 'finds the correct tweets', :vcr do
|
|
26
|
-
expect(replacer.search.first.text).to match /
|
|
27
|
-
# expect(replacer.search.all? { |tweet| tweet.text.match /
|
|
26
|
+
expect(replacer.search.first.text).to match /joe root/i
|
|
27
|
+
# expect(replacer.search.all? { |tweet| tweet.text.match /(detect|predict)/i }).to eq true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'search helper' do
|
|
32
|
+
it 'matches against extra search terms' do
|
|
33
|
+
Config.instance.config.extra_search_terms = [ "predict", "future" ]
|
|
34
|
+
expect(ReplacerBot.has_extra_terms string: "foo").to eq false
|
|
35
|
+
expect(ReplacerBot.has_extra_terms string: "foo in the future").to eq true
|
|
28
36
|
end
|
|
29
37
|
|
|
30
|
-
it '
|
|
31
|
-
|
|
38
|
+
it 'does the right thing with no extra terms' do
|
|
39
|
+
Config.instance.config.extra_search_terms = nil
|
|
40
|
+
expect(ReplacerBot.has_extra_terms string: "foo").to eq true
|
|
32
41
|
end
|
|
33
42
|
end
|
|
34
43
|
end
|
|
@@ -53,16 +53,9 @@ module ReplacerBot
|
|
|
53
53
|
it 'filters retweets' do
|
|
54
54
|
expect(ReplacerBot.validate string: 'RT @xyz This is about Open Data').to eq false
|
|
55
55
|
end
|
|
56
|
-
|
|
57
56
|
it 'filters direct replies' do
|
|
58
57
|
expect(ReplacerBot.validate string: '@abc This is a reply about Open Data').to eq false
|
|
59
58
|
end
|
|
60
|
-
|
|
61
|
-
it 'knows what a Complex Search is' do
|
|
62
|
-
expect(ReplacerBot.complex_search string: 'this OR that').to eq true
|
|
63
|
-
expect(ReplacerBot.complex_search string: 'this AND that').to eq true
|
|
64
|
-
expect(ReplacerBot.complex_search string: 'this, that').to eq false
|
|
65
|
-
end
|
|
66
59
|
end
|
|
67
60
|
|
|
68
61
|
context 'search and replace' do
|