memetron 0.1.1

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.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - ruby-head
5
+ - rbx-19mode
6
+
7
+ env:
8
+ - JRUBY_OPTS="--1.9"
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ end
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ memetron (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rake (0.9.2.2)
11
+ rspec (2.8.0)
12
+ rspec-core (~> 2.8.0)
13
+ rspec-expectations (~> 2.8.0)
14
+ rspec-mocks (~> 2.8.0)
15
+ rspec-core (2.8.0)
16
+ rspec-expectations (2.8.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.8.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ memetron!
25
+ rake
26
+ rspec
@@ -0,0 +1,23 @@
1
+ # Memetron 5000
2
+
3
+ Recognize common internet memes using regular expressions.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/LTe/memetron.png)](http://travis-ci.org/LTe/memetron) [![Dependency Status](https://gemnasium.com/LTe/memetron.png)](https://gemnasium.com/LTe/memetron)
6
+
7
+ ## How
8
+
9
+ ```ruby
10
+ require 'lib/memetron'
11
+
12
+ matcher = Memetron::Matcher.new
13
+
14
+ matcher.match("North Korea is Best Korea") #=> :is_best
15
+
16
+ matcher.parse("Wrote a Ruby library, better drink my own piss") #=> ["Wrote a Ruby library,"]
17
+
18
+ matcher.match_and_parse("I can has meme parsed?") #=> [:i_can_haz, ["meme parsed?"]]
19
+ ```
20
+
21
+ ## Why?
22
+
23
+ For the lulz.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.rspec_opts = ['-fd -c']
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require 'memetron/matcher'
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), 'memes')
2
+
3
+ module Memetron
4
+ class Matcher
5
+ # Attempt to identify the meme in a string.
6
+ def match(string)
7
+ first_match = MEMES.detect { |meme, regexp| string =~ regexp }
8
+ if first_match.nil?
9
+ nil
10
+ else
11
+ meme_name(first_match)
12
+ end
13
+ end
14
+
15
+ # Return variable regions of meme
16
+ def parse(meme, string)
17
+ MEMES[meme].match(string).to_a[1..-1]
18
+ end
19
+
20
+ # Match and parse a meme
21
+ #=> [:meme_name, ['parsed', 'meme', 'bits']]
22
+ def match_and_parse(string)
23
+ meme = match(string)
24
+ if meme.nil?
25
+ return meme
26
+ end
27
+ bits = parse(meme, string)
28
+ [meme, bits]
29
+ end
30
+
31
+ private
32
+
33
+ def meme_name(meme_pair)
34
+ meme_pair[0]
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ module Memetron
2
+ MEMES = {
3
+ # "a wild ruby library appears"
4
+ :pokemon => /a wild (.+) appears/i,
5
+
6
+ # "I don't always write regexp but when I do they break"
7
+ :dos_equis => /I don'?t always (.+) but when I do (.+)/i,
8
+
9
+ # "North Korea is best Korea"
10
+ :is_best => /(\w+\b) (\w+\b) is best (\w+\b)/i,
11
+
12
+ # Yo dawg I heard you like regexp so I put a regexp in your regexp so you can blah
13
+ :yo_dawg => /yo dawg I hea?rd you like (.+) so I put a (.+) in your (.+) so you can (.+) while you (.+)/i,
14
+
15
+ # cant tell if this project is going to go anywhere or just end up on the bottom of my github profile
16
+ # not sure if blah or blah
17
+ :fry => /(can'?t tell|not sure) if (.+) or (.+)/i,
18
+
19
+ # lets take all the memes and put them over here
20
+ :patrick => /let'?s take all the (.+) and put them over here/i,
21
+
22
+ # "soon" or "soon." or "soon..."
23
+ :soon => /^soon(\.|\.{3})?$/i,
24
+
25
+ # Y U NO DO THIS?
26
+ :y_u_no? => /(.*)Y U NO (.+)\?/i,
27
+
28
+ # Hipster Kitty
29
+ :hipster_kitty => /I liked (.*) before (.*)/i,
30
+
31
+ # Bear Grylls
32
+ :bear_grylls => /(.*) better drink my own piss/i,
33
+
34
+ # I can haz cheeseburger
35
+ :i_can_haz => /I can ha[zs] (.*)/i,
36
+
37
+ # Jimmy McMillan is too damn high!
38
+ :jimmy_mcmillan => /(.*) is too damn high!/i,
39
+
40
+ # I find your lack of tests disturbing
41
+ :darth_vader => /I find your lack of (.*) disturbing/i,
42
+
43
+ # Prepare yourself, the procedurally generated memes are coming
44
+ :sean_bean => /Prepare yourself,? the (.*) are coming/i,
45
+ }
46
+ end
@@ -0,0 +1,3 @@
1
+ module Memetron
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'memetron/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "memetron"
7
+ s.version = Memetron::VERSION
8
+ s.authors = ["Piotr Niełacny"]
9
+ s.email = ["piotr.nielacny@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Recognize common internet memes using regular expressions}
12
+ s.description = %q{Recognize common internet memes using regular expressions}
13
+
14
+ s.rubyforge_project = "memetron"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+
3
+ describe Memetron::Matcher, "#match" do
4
+ it "returns nil if no match was found" do
5
+ subject.match("blerg blerg blerg").should be_nil
6
+ end
7
+
8
+ it "can match and parse a meme" do
9
+ subject.match_and_parse("a wild charizard appears").should == [:pokemon, ['charizard']]
10
+ end
11
+
12
+ it "returns nil if no match was found" do
13
+ subject.match_and_parse('blerg blerg blerg').should be_nil
14
+ end
15
+
16
+ it "when multiple memes are present, the first match in memes.rb will be used. if this test fails it's because the order of memes changed." do
17
+ subject.match_and_parse('not sure if i can haz cheeseburger or better drink my own piss?').should == [:fry, ["not sure", "i can haz cheeseburger", "better drink my own piss?"]]
18
+ end
19
+
20
+ context "Pokemon" do
21
+ it "is detected" do
22
+ subject.match("a wild charizard appears").should == :pokemon
23
+ end
24
+
25
+ it "requires a subject" do
26
+ subject.match("a wild appears").should be_nil
27
+ end
28
+
29
+ it "is parsed" do
30
+ subject.parse(:pokemon, "a wild charizard appears").should == ['charizard']
31
+ end
32
+ end
33
+
34
+ context "Dos Equis" do
35
+ it "is detected" do
36
+ subject.match("I don't always go crazy but when i do i go all the way").should == :dos_equis
37
+ end
38
+
39
+ it "is detected despite poor grammar" do
40
+ subject.match("I dont always go crazy but when I do I go all the way").should == :dos_equis
41
+ end
42
+
43
+ it "is parsed" do
44
+ subject.parse(:dos_equis, "I don't always x but when I do y").should == ['x', 'y']
45
+ end
46
+ end
47
+
48
+ context "Is best" do
49
+ it "is detected" do
50
+ subject.match("north korea is best korea").should == :is_best
51
+ end
52
+
53
+ it "is parsed" do
54
+ subject.parse(:is_best, "north korea is best korea").should == ["north", "korea", "korea"]
55
+ end
56
+ end
57
+
58
+ context "Yo dawg" do
59
+ it "is detected" do
60
+ subject.match("yo dawg i heard you like stereos so i put a stereo in your car so you can listen while you listen").should == :yo_dawg
61
+ end
62
+
63
+ it "is detected despite poor grammar" do
64
+ subject.match("yo dawg i herd you like stereos so i put a stereo in your car so you can listen while you listen").should == :yo_dawg
65
+ end
66
+
67
+ it "is parsed" do
68
+ subject.parse(:yo_dawg, "yo dawg i heard you like stereos so i put a stereo in your car so you can listen while you listen").should == ['stereos', 'stereo', 'car', 'listen', 'listen']
69
+ end
70
+ end
71
+
72
+ context "Fry" do
73
+ it %q(is detected with "Can't tell") do
74
+ subject.match("can't tell if joking or not").should == :fry
75
+ end
76
+
77
+ it 'is detected with "Not sure"' do
78
+ subject.match("not sure if joking or not").should == :fry
79
+ end
80
+
81
+ it "is parsed" do
82
+ subject.parse(:fry, "cant tell if joking or not").should == ['cant tell', 'joking', 'not']
83
+ end
84
+ end
85
+
86
+ context "Patrick" do
87
+ it "is detected" do
88
+ subject.match("let's take all the languages and put them over here").should == :patrick
89
+ end
90
+
91
+ it "is detected despite poor grammar" do
92
+ subject.match("lets take all the languages and put them over here").should == :patrick
93
+ end
94
+
95
+ it "is parsed" do
96
+ subject.parse(:patrick, "let's take all the languages and put them over here").should == ['languages']
97
+ end
98
+ end
99
+
100
+ context "SOON" do
101
+ it "is detected when it's by itself" do
102
+ subject.match("SOON").should == :soon
103
+ end
104
+
105
+ it "is case-insensitive" do
106
+ subject.match("soon").should == :soon
107
+ end
108
+
109
+ it "is detected when it's a sentence" do
110
+ subject.match("SOON.").should == :soon
111
+ end
112
+
113
+ it "is detected with an ellipsis" do
114
+ subject.match("SOON...").should == :soon
115
+ end
116
+
117
+ it "is parsed" do
118
+ subject.parse(:soon, "SOON...").should == ['...']
119
+ end
120
+ end
121
+
122
+ context "Y U NO" do
123
+ it "is detected when it begins the sentence" do
124
+ subject.match("Y U NO DO THIS?").should == :y_u_no?
125
+ end
126
+
127
+ it "is detected when it does not begin the sentence" do
128
+ subject.match("PROGRAMMERS, Y U NO DO THIS?").should == :y_u_no?
129
+ end
130
+
131
+ it "requires a question mark" do
132
+ subject.match("PROGRAMMERS, Y U NO DO THIS").should be_nil
133
+ end
134
+
135
+ it "is parsed" do
136
+ subject.parse(:y_u_no?, "Y U NO DO THIS?").should == ['', 'DO THIS']
137
+ end
138
+ end
139
+
140
+ context "Hipster Kitty" do
141
+ it "is detected" do
142
+ subject.match("I liked Ruby before Matz was born").should == :hipster_kitty
143
+ end
144
+
145
+ it "is parsed" do
146
+ subject.parse(:hipster_kitty, "I liked Ruby before Matz was born").should == ['Ruby', 'Matz was born']
147
+ end
148
+ end
149
+
150
+ context "Bear Grylls" do
151
+ it "is detected" do
152
+ subject.match("Write a Ruby library. Better drink my own piss").should == :bear_grylls
153
+ end
154
+
155
+ it "is parsed" do
156
+ subject.parse(:bear_grylls, "Write a Ruby library. Better drink my own piss").should == ["Write a Ruby library."]
157
+ end
158
+ end
159
+
160
+ context "I can haz" do
161
+ it "is detected" do
162
+ subject.match("I can haz Ruby library?").should == :i_can_haz
163
+ end
164
+
165
+ it "should work with either has or haz" do
166
+ subject.match("I can has Ruby library?").should == :i_can_haz
167
+ end
168
+
169
+ it "is parsed" do
170
+ subject.parse(:i_can_haz, "I can haz Ruby library?").should == ['Ruby library?']
171
+ end
172
+ end
173
+
174
+ context "Jimmy McMillan" do
175
+ it "is detected" do
176
+ subject.match("The level of information is too damn high!").should == :jimmy_mcmillan
177
+ end
178
+
179
+ it "should only match when an exclamation mark is present" do
180
+ subject.match("The level of information is too damn high").should be_nil
181
+ end
182
+
183
+ it "is parsed" do
184
+ subject.parse(:jimmy_mcmillan, "The level of information is too damn high!").should == ["The level of information"]
185
+ end
186
+ end
187
+
188
+ context "Darth Vader" do
189
+ it "is detected" do
190
+ subject.match("I find your lack of tests disturbing").should == :darth_vader
191
+ end
192
+
193
+ it "is parsed" do
194
+ subject.parse(:darth_vader, "I find your lack of tests disturbing").should == ["tests"]
195
+ end
196
+ end
197
+
198
+ context "Sean Bean" do
199
+ it "is matched" do
200
+ subject.match("Prepare yourself, the memes are coming").should == :sean_bean
201
+ end
202
+
203
+ it "is parsed" do
204
+ subject.parse(:sean_bean, "Prepare yourself, the memes are coming").should == ["memes"]
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), "lib")
2
+
3
+ require 'rspec'
4
+ require 'memetron'
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memetron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Piotr Niełacny
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Recognize common internet memes using regular expressions
15
+ email:
16
+ - piotr.nielacny@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .rspec
22
+ - .travis.yml
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - README.md
26
+ - Rakefile
27
+ - lib/memetron.rb
28
+ - lib/memetron/.version.rb.swp
29
+ - lib/memetron/matcher.rb
30
+ - lib/memetron/memes.rb
31
+ - lib/memetron/version.rb
32
+ - memetron.gemspec
33
+ - spec/memetron/matcher_spec.rb
34
+ - spec/spec_helper.rb
35
+ homepage: ''
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project: memetron
55
+ rubygems_version: 1.8.10
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Recognize common internet memes using regular expressions
59
+ test_files: []
60
+ has_rdoc: