replacer_bot 0.1.1.pre.rc1 → 0.1.1.pre.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2a369cf5d62f75a206c64ec2f2fed6490b688c3
4
- data.tar.gz: ace466966daaf290e16b44055d7dd41b64267474
3
+ metadata.gz: 3826a9d118356a0f052648585a26e6a0583b570a
4
+ data.tar.gz: badfd138905d15a4ca6dc52d8c11d0ff04207c61
5
5
  SHA512:
6
- metadata.gz: 1ae3d0d9c21d8f7059ce1bf76fc22d226edcc8ba4364389b1b0851ff4830f881c69910617bc8d2ae3934766d8abcd442c6b9f0133a5763b966837d06f26731b4
7
- data.tar.gz: e0823bf012f30e62ebd4f8eb4f2d33fe9f2c57a522e8a11d3770d57c9370a68bd3a2bfa521db52a630445b8bea74fa8ee16039f243a16e411343da9090c6de65
6
+ metadata.gz: 72c4e941085e4ecf3406ab028584b999683e9b952f057fccf9cbaf78adfc70ded5e294bb423d5bf2d49ad7f2632517c30cda9d0ed015d7be5c3553b7202bb1fc
7
+ data.tar.gz: a8c07e4495fa7e81c39fe4ee969dd6dc0e9d820ee9c6edc72a1ad846bcda97fdf5baf40ab67a36ba9f7996d87001ed145173595bc218d305718d73c58452598c
@@ -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
- unless self.complex_search(string: term)
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]
@@ -1,3 +1,3 @@
1
1
  module ReplacerBot
2
- VERSION = "0.1.1-rc1"
2
+ VERSION = "0.1.1-rc2"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  module ReplacerBot
2
2
  describe Replacer do
3
3
  before :each do
4
- # Config.instance.config.search_term = "artificial intelligence AND (detect OR predict)"
5
- Config.instance.config.search_term = "everton AND (koeman OR goodison)"
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 /everton/i
27
- # expect(replacer.search.all? { |tweet| tweet.text.match /everton/i }).to eq true
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 'finds English tweets', :vcr do
31
- expect(replacer.search.all? { |tweet| tweet.lang == 'en' }).to eq true
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