replacer_bot 0.0.11 → 0.0.12

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: cb6eb41749b23d020804bf0742e58038203fe835
4
- data.tar.gz: 59e58888b936c5ee0530c0346f0fb6e16f083bf3
3
+ metadata.gz: ffcdcb7270536586d24989893fa20d573fdb8077
4
+ data.tar.gz: 6f1b51639c893c64794e3474607a4d1b0d40c93d
5
5
  SHA512:
6
- metadata.gz: ffe86fa7c354bfaf4b246901e190438dba1c5f7c8f8b48315baa1a6b3540e81c8b1bad9760f3391fdbae24259cc86219161ba031330d98e3938ea4ee18f2ebbf
7
- data.tar.gz: 5a74cd8bc656f5f11d025438406563c7ad8433be49c79c5933da1b1ba844faf5bba57cd5a9b6e8f1f590b468c353ffcb597c0bcb3dfc242a5ac52e1e41d22203
6
+ metadata.gz: 62dd59e12a164d1f9d224ef81d6c600e9115bbc26728aa46b443cbfeb6b014e3b7749a5ca82bbd85dd589d49f8e1bfefc48c2de42414ecd2cad87eea8f636bc1
7
+ data.tar.gz: 3022ceb0602188353b78c7e99275d5d35867cc2083ed5efade5e189f7ca273fb131c74aaeface9615724b516c1118bb05f21eed19a76dfa34853432462baae41
data/config/defaults.yml CHANGED
@@ -5,7 +5,7 @@ ignore_spaces: true
5
5
  save_file: last.tweet
6
6
  seen_tweets: seen.tweets
7
7
  replacements:
8
- - open data: Taylor Swift
8
+ - Open Data: Taylor Swift
9
9
  - opendata: TaylorSwift
10
10
  interval: 60 #seconds
11
11
  similarity_weighting: 4 # how many words a tweet must overlap already-seen tweets by for us to consider it 'similar'
@@ -1,3 +1,16 @@
1
+ class String
2
+ def titlecase
3
+ bits = self.split ''
4
+ bits[0] = UnicodeUtils.upcase(bits[0])
5
+
6
+ bits.join ''
7
+ end
8
+
9
+ def upcase
10
+ UnicodeUtils.upcase self
11
+ end
12
+ end
13
+
1
14
  module ReplacerBot
2
15
  def self.encode term:
3
16
  URI.encode "\"#{term}\""
@@ -51,7 +64,7 @@ module ReplacerBot
51
64
 
52
65
  def self.title_case string
53
66
  bits = string.split ''
54
- bits[0] = bits[0].upcase
67
+ bits[0] = UnicodeUtils.upcase(bits[0])
55
68
 
56
69
  bits.join ''
57
70
  end
@@ -85,6 +98,15 @@ module ReplacerBot
85
98
  'a'
86
99
  end
87
100
 
101
+ def self.replacement_caser replacement
102
+ l = []
103
+ l.push({replacement.first[0].upcase => replacement.first[1].upcase})
104
+ l.push({replacement.first[0].downcase => replacement.first[1]})
105
+ l.push({replacement.first[0].titlecase => replacement.first[1]})
106
+
107
+ l.uniq
108
+ end
109
+
88
110
  def self.replacement_extender replacement
89
111
  [
90
112
  replacement.map { |k, v| {"#{self.article k} #{k}" => "#{self.article v} #{v}"} }[0],
@@ -95,6 +117,15 @@ module ReplacerBot
95
117
  def self.replace string:, subs: Config.instance.config.replacements
96
118
  # Something about a frozen string
97
119
  our_string = string.dup
120
+ subs.map { |s| self.replacement_caser(s) }.flatten.each do |substitute|
121
+ (self.replacement_extender(substitute) << substitute).each do |s|
122
+ s.each do |search, replace|
123
+ our_string = self.despace our_string
124
+ our_string.gsub! /#{search}/, replace
125
+ end
126
+ end
127
+ end
128
+
98
129
  subs.each do |substitute|
99
130
  (self.replacement_extender(substitute) << substitute).each do |s|
100
131
  s.each do |search, replace|
@@ -1,3 +1,3 @@
1
1
  module ReplacerBot
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/lib/replacer_bot.rb CHANGED
@@ -5,6 +5,7 @@ require 'singleton'
5
5
  require 'thor'
6
6
  require 'yaml'
7
7
  require 'htmlentities'
8
+ require 'unicode_utils/upcase'
8
9
 
9
10
  require 'replacer_bot/version'
10
11
  require 'replacer_bot/replacer'
@@ -16,4 +17,4 @@ require 'replacer_bot/twitter_client'
16
17
  Dotenv.load
17
18
  Dotenv.load "#{ENV['HOME']}/.replacer_botrc"
18
19
 
19
- TWITTER_LIMIT= 140
20
+ TWITTER_LIMIT = 140
data/replacer_bot.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'dotenv', '~> 2.0'
23
23
  spec.add_dependency 'thor', '~> 0.19'
24
24
  spec.add_dependency 'htmlentities', '~> 4.3'
25
+ spec.add_dependency 'unicode_utils', '~> 1.4'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.7'
27
28
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -79,9 +79,36 @@ 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
+ end
101
+
102
+ it 'preserves case when replacing' do
103
+ expect(ReplacerBot.replace string: 'Open Data').to eq 'Taylor Swift'
104
+ expect(ReplacerBot.replace string: 'OPEN DATA').to eq 'TAYLOR SWIFT'
105
+ expect(ReplacerBot.replace string: 'OPEN DATA Open Data open data').to eq 'TAYLOR SWIFT Taylor Swift Taylor Swift'
106
+ end
107
+
82
108
  it 'replaces text' do
83
109
  expect(ReplacerBot.replace string: 'Something about Open Data goes here').to eq 'Something about Taylor Swift goes here'
84
110
  expect(ReplacerBot.replace string: 'Something about #opendata http://foo.bar/').to eq 'Something about #TaylorSwift http://foo.bar/'
111
+ expect(ReplacerBot.replace string: 'OPEN DATA things and an #OpenData hashtag and this OPen DatA').to eq 'TAYLOR SWIFT things and a #TaylorSwift hashtag and this Taylor Swift'
85
112
  end
86
113
 
87
114
  it 'does a/an correctly' do
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.11
4
+ version: 0.0.12
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-05 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: unicode_utils
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.4'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -309,3 +323,4 @@ test_files:
309
323
  - spec/vcr/ReplacerBot_Replacer/tweet/actually_sends_tweets.yml
310
324
  - spec/vcr/ReplacerBot_Replacer/tweet/prepares_sensible_tweets.yml
311
325
  - spec/vcr/ReplacerBot_Replacer/tweet/sends_no_tweets_on_a_dry-run.yml
326
+ has_rdoc: