replacer_bot 0.0.13 → 0.0.14
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/README.md +4 -1
- data/config/defaults.yml +1 -0
- data/lib/replacer_bot/helpers.rb +1 -1
- data/lib/replacer_bot/seen_tweets.rb +11 -1
- data/lib/replacer_bot/version.rb +1 -1
- data/spec/lib/replacer_bot/case_spec.rb +41 -0
- data/spec/lib/replacer_bot/helpers_spec.rb +0 -35
- data/spec/lib/replacer_bot/seen_tweets_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad595f8f205c0125c27951dd1c71547bb460afd1
|
4
|
+
data.tar.gz: 95f74b265bf1278d9e84c2fac3efc108806a24e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98c1ffe621cbdcb9dac2723df758ec3b7117aa87e324662f2f4c3e1dbe87b080c106602b65d80241f41b1ecdc0de3f1cd7f9fa9feaca6264f7be2db69daf9d78
|
7
|
+
data.tar.gz: 627097f0f0063258534404ad9a164df4c825960b8f6781e56442e756a7b773fd4eb70eb0dce7bc3ef7658fc2b8f4a691b1f753700b0610ac0c8ddd0b087a5f0e
|
data/README.md
CHANGED
@@ -40,7 +40,10 @@ The default config is [here](https://github.com/pikesley/replacer_bot/blob/maste
|
|
40
40
|
Notes:
|
41
41
|
|
42
42
|
* The search-and-replace terms will be applied in the order listed, which you may or may not care about
|
43
|
-
* The search
|
43
|
+
* The search and replace has a number of passes based on some of my finger-in-the-air Reckons, which are probably easiest to understand via the [specs](https://github.com/pikesley/replacer_bot/blob/master/spec/lib/replacer_bot/case_spec.rb). After it tries each of these search-and-replace operations, it does a case-insensitive regex search-and-replace using the raw terms from the YAML (in order to catch SHittily-typeD things, because Twitter is a mess)
|
44
|
+
* Your takeaway from this should be that if your replacement is a name or whatever, put it in the YAML Titlecased, otherwise lowercase it, and it should do the Right Thing
|
45
|
+
|
46
|
+
### Twitter credentials
|
44
47
|
|
45
48
|
You'll also need some Twitter credentials, store them in `~/.replacer_botrc` like this:
|
46
49
|
|
data/config/defaults.yml
CHANGED
data/lib/replacer_bot/helpers.rb
CHANGED
@@ -121,7 +121,7 @@ module ReplacerBot
|
|
121
121
|
(self.replacement_extender(substitute) << substitute).each do |s|
|
122
122
|
s.each do |search, replace|
|
123
123
|
our_string = self.despace our_string
|
124
|
-
our_string.gsub!
|
124
|
+
our_string.gsub! search, replace
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
@@ -75,9 +75,19 @@ module ReplacerBot
|
|
75
75
|
nuke_hashtags clean_urls tweet
|
76
76
|
end
|
77
77
|
|
78
|
+
def self.unshift set
|
79
|
+
a = set.to_a
|
80
|
+
max_size = Config.instance.config.max_seen_tweets
|
81
|
+
if a.count > max_size
|
82
|
+
a = a[-max_size..-1]
|
83
|
+
end
|
84
|
+
|
85
|
+
Set.new a
|
86
|
+
end
|
87
|
+
|
78
88
|
def self.save set
|
79
89
|
File.open Config.instance.config.seen_tweets, 'w' do |file|
|
80
|
-
Marshal.dump set, file
|
90
|
+
Marshal.dump unshift(set), file
|
81
91
|
end
|
82
92
|
end
|
83
93
|
end
|
data/lib/replacer_bot/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module ReplacerBot
|
2
|
+
describe 'Helpers' do
|
3
|
+
context 'case handling' do
|
4
|
+
it 'has case variants for replacements' do
|
5
|
+
expect(ReplacerBot.replacement_caser 'Open Data' => 'Taylor Swift').
|
6
|
+
to eq(
|
7
|
+
[
|
8
|
+
{'OPEN DATA' => 'TAYLOR SWIFT'},
|
9
|
+
{'open data' => 'Taylor Swift'},
|
10
|
+
{'Open Data' => 'Taylor Swift'}
|
11
|
+
]
|
12
|
+
)
|
13
|
+
|
14
|
+
expect(ReplacerBot.replacement_caser 'blockchain' => 'Beyoncé').
|
15
|
+
to eq(
|
16
|
+
[
|
17
|
+
{'BLOCKCHAIN' => 'BEYONCÉ'},
|
18
|
+
{'blockchain' => 'Beyoncé'},
|
19
|
+
{'Blockchain' => 'Beyoncé'}
|
20
|
+
]
|
21
|
+
)
|
22
|
+
|
23
|
+
expect(ReplacerBot.replacement_caser 'cyber' => 'spider').
|
24
|
+
to eq(
|
25
|
+
[
|
26
|
+
{'CYBER' => 'SPIDER'},
|
27
|
+
{'cyber' => 'spider'},
|
28
|
+
{'Cyber' => 'Spider'}
|
29
|
+
]
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'preserves case when replacing' do
|
34
|
+
expect(ReplacerBot.replace string: 'Open Data').to eq 'Taylor Swift'
|
35
|
+
expect(ReplacerBot.replace string: 'OPEN DATA').to eq 'TAYLOR SWIFT'
|
36
|
+
expect(ReplacerBot.replace string: 'OPEn DAta').to eq 'Taylor Swift'
|
37
|
+
expect(ReplacerBot.replace string: 'OPEN DATA Open Data open data').to eq 'TAYLOR SWIFT Taylor Swift Taylor Swift'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -79,41 +79,6 @@ module ReplacerBot
|
|
79
79
|
to eq 'FYI via @DBMph: The 2016 proposed budget is now in Taylor Swift format! You may access it on our website: http://t.co/EO6Lep3PeW'
|
80
80
|
end
|
81
81
|
|
82
|
-
it 'has case variants for replacements' do
|
83
|
-
expect(ReplacerBot.replacement_caser 'Open Data' => 'Taylor Swift').
|
84
|
-
to eq(
|
85
|
-
[
|
86
|
-
{'OPEN DATA' => 'TAYLOR SWIFT'},
|
87
|
-
{'open data' => 'Taylor Swift'},
|
88
|
-
{'Open Data' => 'Taylor Swift'}
|
89
|
-
]
|
90
|
-
)
|
91
|
-
|
92
|
-
expect(ReplacerBot.replacement_caser 'blockchain' => 'Beyoncé').
|
93
|
-
to eq(
|
94
|
-
[
|
95
|
-
{'BLOCKCHAIN' => 'BEYONCÉ'},
|
96
|
-
{'blockchain' => 'Beyoncé'},
|
97
|
-
{'Blockchain' => 'Beyoncé'}
|
98
|
-
]
|
99
|
-
)
|
100
|
-
|
101
|
-
expect(ReplacerBot.replacement_caser 'cyber' => 'spider').
|
102
|
-
to eq(
|
103
|
-
[
|
104
|
-
{'CYBER' => 'SPIDER'},
|
105
|
-
{'cyber' => 'spider'},
|
106
|
-
{'Cyber' => 'Spider'}
|
107
|
-
]
|
108
|
-
)
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'preserves case when replacing' do
|
112
|
-
expect(ReplacerBot.replace string: 'Open Data').to eq 'Taylor Swift'
|
113
|
-
expect(ReplacerBot.replace string: 'OPEN DATA').to eq 'TAYLOR SWIFT'
|
114
|
-
expect(ReplacerBot.replace string: 'OPEN DATA Open Data open data').to eq 'TAYLOR SWIFT Taylor Swift Taylor Swift'
|
115
|
-
end
|
116
|
-
|
117
82
|
it 'replaces text' do
|
118
83
|
expect(ReplacerBot.replace string: 'Something about Open Data goes here').to eq 'Something about Taylor Swift goes here'
|
119
84
|
expect(ReplacerBot.replace string: 'Something about #opendata http://foo.bar/').to eq 'Something about #TaylorSwift http://foo.bar/'
|
@@ -116,5 +116,20 @@ module ReplacerBot
|
|
116
116
|
expect(Marshal.load File.open Config.instance.config.seen_tweets).to include 1
|
117
117
|
expect(Marshal.load File.open Config.instance.config.seen_tweets).to include 3
|
118
118
|
end
|
119
|
+
|
120
|
+
it 'keeps a set to reasonable size' do
|
121
|
+
a = []
|
122
|
+
1010.times do |i|
|
123
|
+
a.push i
|
124
|
+
end
|
125
|
+
set = Set.new a
|
126
|
+
|
127
|
+
described_class.save set
|
128
|
+
expect(Marshal.load File.open Config.instance.config.seen_tweets).to be_a Set
|
129
|
+
expect(Marshal.load(File.open(Config.instance.config.seen_tweets)).count).to eq 1000
|
130
|
+
expect(Marshal.load File.open Config.instance.config.seen_tweets).to include 1000
|
131
|
+
expect(Marshal.load File.open Config.instance.config.seen_tweets).not_to include 0
|
132
|
+
expect(Marshal.load File.open Config.instance.config.seen_tweets).not_to include 9
|
133
|
+
end
|
119
134
|
end
|
120
135
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: replacer_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pikesley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- lib/replacer_bot/twitter_client.rb
|
251
251
|
- lib/replacer_bot/version.rb
|
252
252
|
- replacer_bot.gemspec
|
253
|
+
- spec/lib/replacer_bot/case_spec.rb
|
253
254
|
- spec/lib/replacer_bot/config_spec.rb
|
254
255
|
- spec/lib/replacer_bot/helpers_spec.rb
|
255
256
|
- spec/lib/replacer_bot/replacer_spec.rb
|
@@ -300,6 +301,7 @@ summary: Search, mangle and tweet
|
|
300
301
|
test_files:
|
301
302
|
- features/replacer.feature
|
302
303
|
- features/support/env.rb
|
304
|
+
- spec/lib/replacer_bot/case_spec.rb
|
303
305
|
- spec/lib/replacer_bot/config_spec.rb
|
304
306
|
- spec/lib/replacer_bot/helpers_spec.rb
|
305
307
|
- spec/lib/replacer_bot/replacer_spec.rb
|