snarkify 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTY5YmZmOGM2ODQzYjVkYWUyOWRjNjU3MWUwNjdhMTQ4NjQxODE3Yw==
5
+ data.tar.gz: !binary |-
6
+ NTU1ZTQ3ODZkNjkyMDEyODRmMWJkMjRlMzI4ZDc2ZGVhZTc0MjAzYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZWQzMzljMjBkMDhmMmE0OTA2ZTMxZjZhNDFkZGM3ZjU5N2MwNjhkZTU2YWUy
10
+ NTVhNTg4OWY1Mjk1YmUwYjNlZjExZjMzMGY1YjE4MTU4YzY2NGQwMmZiZDcw
11
+ ZDhkODY3MWZmZTFlYTZiNjk4YjE3NGZjZDdkN2JkNmY1ZjBlYjU=
12
+ data.tar.gz: !binary |-
13
+ NTE2YjNmZjNiOTY3MjBkM2EyN2E5M2M0ZjNmMjAyOWM4NzVhN2VjMWI2YzUx
14
+ NjA0MjZjMDRlZWVkNGQ0YzU4Y2MyNzJjOWNiZDRjNmVjYWU5MjhiN2U3NDBk
15
+ Yzk5YjJiN2QwZDYxZmU2NDAwOGI3MDRiZmY0MTFhZTllMjI3NTE=
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ snarkify (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.3)
16
+ rake
17
+ snarkify!
@@ -0,0 +1,16 @@
1
+ snarkify
2
+ ========
3
+
4
+ A gem to replace positive words with insults
5
+
6
+ # TODO
7
+ * create sample JSON file
8
+ -good word:bad words
9
+ -index:{good words:bad words}
10
+ * load JSON file
11
+ * parse load into word objects
12
+ * method to search for good words and replace with bad
13
+
14
+ * build gem
15
+ * submit to rubygems
16
+ * download and test
data/gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,6 @@
1
+ require_relative './snarkify/snarkify'
2
+ require_relative './snarkify/word_substitution'
3
+ require_relative './snarkify/dictionary'
4
+ require_relative './snarkify/dictionary_parser'
5
+ require_relative './snarkify/dictionary_loader'
6
+ require_relative './snarkify/word_replacer'
@@ -0,0 +1,8 @@
1
+ require 'yaml'
2
+
3
+ class Dictionary
4
+ def self.get_word_substitutions(filename)
5
+ dictionary = DictionaryLoader.load_dictionary(filename)
6
+ word_substitions = DictionaryParser.parse_dictionary(dictionary)
7
+ end
8
+ end
@@ -0,0 +1,103 @@
1
+ ---
2
+ - good:
3
+ - love
4
+ - like
5
+ - enjoy
6
+ - appreciate
7
+ - adore
8
+ bad:
9
+ - hate
10
+ - despise
11
+ - resent
12
+ - dislike
13
+ - detest
14
+
15
+ - good:
16
+ - happy
17
+ - joyful
18
+ - excited
19
+ - cheerful
20
+ - content
21
+ - delighted
22
+ - glad
23
+ - pleased
24
+ - thrilled
25
+ - calm
26
+ bad:
27
+ - angry
28
+ - pissed
29
+ - resentful
30
+ - disappointed
31
+ - miserable
32
+ - troubled
33
+ - morose
34
+ - enraged
35
+ - furious
36
+ - offended
37
+ - insulted
38
+ - vexed
39
+ - incensed
40
+
41
+ - good:
42
+ - cool
43
+ - awesome
44
+ - great
45
+ - magnificent
46
+ - stunning
47
+ - wonderful
48
+ - fine
49
+ - brilliant
50
+ - excellent
51
+ - marvelous
52
+ - superb
53
+ - super
54
+ - good
55
+ bad:
56
+ - terrible
57
+ - shite
58
+ - bollocks
59
+ - crap
60
+ - wank
61
+ - drivel
62
+
63
+ - good:
64
+ - beautiful
65
+ - gorgeous
66
+ - lovely
67
+ - cute
68
+ - charming
69
+ - good looking
70
+ - handsome
71
+ - magnificent
72
+ - pretty
73
+ - amazing
74
+ - incredible
75
+ bad:
76
+ - ugly
77
+ - hideous
78
+ - grotesque
79
+ - deformed
80
+ - gross
81
+
82
+ - good:
83
+ - friend
84
+ - pal
85
+ - mate
86
+ - buddy
87
+ - partner
88
+ - wife
89
+ - husband
90
+ - girlfriend
91
+ - boyfriend
92
+ bad:
93
+ - enemy
94
+ - asshole
95
+ - tosser
96
+ - tosspot
97
+ - foe
98
+ - nemesis
99
+
100
+ - good:
101
+ - miss you
102
+ bad:
103
+ - hope you die in a fire
@@ -0,0 +1,5 @@
1
+ class DictionaryLoader
2
+ def self.load_dictionary(filename)
3
+ YAML.load_file(filename)
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class DictionaryParser
2
+ def self.parse_dictionary(dictionary)
3
+ dictionary.map do |entry|
4
+ WordSubstitution.new(entry)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ FILENAME = File.dirname(__FILE__) + '/dictionary.yml'
2
+
3
+ class Snarkify
4
+ def self.replace_words(content, filename=FILENAME)
5
+ word_substitutions = Dictionary.get_word_substitutions(filename)
6
+ WordReplacer.replace_words(content, word_substitutions)
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class WordReplacer
2
+ def self.replace_words(content, substitutions)
3
+ substitutions.each do |substitution|
4
+ substitution.snarkify!(content)
5
+ end
6
+ content
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ class WordSubstitution
2
+ attr_reader :good_words
3
+
4
+ def initialize(params)
5
+ @good_words = params.fetch("good")
6
+ @bad_words = params.fetch("bad")
7
+ end
8
+
9
+ def snarkify!(content)
10
+ @good_words.each do |word|
11
+ content.gsub!(/([^a-zA-Z])#{word}([^a-zA-Z])/im, "\\1#{get_bad_word}\\2")
12
+ end
13
+ content
14
+ end
15
+
16
+ private
17
+
18
+ def get_bad_word
19
+ @bad_words.sample
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'lib/snarkify'
2
+ require 'bundler/gem_tasks'
3
+
4
+ desc "test snarkify"
5
+ task "test" do
6
+ p Snarkify.replace_words("I love!? bananas. I'm really happy! Because I ...LOVE... bananas")
7
+ end
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'snarkify'
6
+ spec.version = '0.0.4'
7
+ spec.date = '2014-08-28'
8
+ spec.summary = "Replace positive words with insults"
9
+ spec.description = "Replaces all the positive words in given content with negative words, taking into account punctuation and larger words, etc"
10
+ spec.authors = ["James Robinson"]
11
+ spec.email = 'james.michael.robinson@gmail.com'
12
+ spec.files = ["lib/snarkify.rb"]
13
+ spec.homepage = 'http://rubygems.org/gems/snarkify'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snarkify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - James Robinson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Replaces all the positive words in given content with negative words,
14
+ taking into account punctuation and larger words, etc
15
+ email: james.michael.robinson@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile.lock
22
+ - README.md
23
+ - gemfile
24
+ - lib/snarkify.rb
25
+ - lib/snarkify/dictionary.rb
26
+ - lib/snarkify/dictionary.yml
27
+ - lib/snarkify/dictionary_loader.rb
28
+ - lib/snarkify/dictionary_parser.rb
29
+ - lib/snarkify/snarkify.rb
30
+ - lib/snarkify/word_replacer.rb
31
+ - lib/snarkify/word_substitution.rb
32
+ - rakefile
33
+ - snarkify.gemspec
34
+ homepage: http://rubygems.org/gems/snarkify
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.1.5
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Replace positive words with insults
58
+ test_files: []