memelicious 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c98d961cd5099a691acba083927b154f57e0bcce
4
+ data.tar.gz: cda424f14b45ecbb9fafd0bd384ceacd1ed005b5
5
+ SHA512:
6
+ metadata.gz: 12a5f475a024826653f287acf32cdc2324e613e4a8853a29bdc98b99b2c1d03871ae8b5b9b72d68b93534a94288a43f7e49ec3fdae9bb306c2c968017e53fb0d
7
+ data.tar.gz: 59673099cd4912ebc39a0a756d552826f732d0f5ae5aa88acfed0e29ea8b701588e8ea59cc71a59af3f7fa2d2b0fe7c8f36bd16d04544b114d76e50ca49801d5
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'memelicious/meme'
5
+
6
+ # require all the memes!
7
+ Dir.glob(File.join(File.dirname(__FILE__), 'memelicious', 'memes', '*.rb')).each { |x| require x }
8
+
9
+ require 'memelicious/matcher'
@@ -0,0 +1,20 @@
1
+ module Memelicious
2
+ class Matcher
3
+ class << self
4
+
5
+
6
+ def match(string)
7
+ Memelicious::Meme.memes.each do |meme|
8
+ match = meme.match(string)
9
+ if match
10
+ return [meme, match]
11
+ end
12
+ end
13
+ return nil
14
+ end
15
+
16
+ alias :[] :match
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,78 @@
1
+ module Memelicious
2
+
3
+ ##
4
+ # This class is inherited by memes and used to do the following
5
+ #
6
+ # - Define the meme using a regular expression
7
+ # - Define what the meme should match
8
+ # - Define what the meme should not match
9
+ # - Define what the meme should return
10
+ #
11
+ class Meme
12
+
13
+ class << self
14
+
15
+ attr_accessor :positive_examples
16
+ attr_accessor :negative_examples
17
+
18
+ def matcher(matcher)
19
+ @matcher_regexp = matcher
20
+ end
21
+
22
+ # this method defines what a meme should match
23
+ def should_match(example)
24
+ @positive_examples ||= Hash.new { |h, k| h[k] = nil }
25
+ @positive_examples[example] = nil
26
+ @last_added = example
27
+ end
28
+
29
+ # this method defines what a meme should not match
30
+ def should_not_match(example)
31
+ @negative_examples ||= Array.new
32
+ @negative_examples << example
33
+ end
34
+
35
+ # this method defines what a meme should return
36
+ # use after calling Meme#should_match
37
+ #
38
+ # For example
39
+ #
40
+ # should_match /this meme should match the following (.*)/
41
+ # and return "what is captured by (.*)
42
+ def and_return(example)
43
+ @positive_examples[@last_added] = example
44
+ end
45
+
46
+ def memes
47
+ ObjectSpace.each_object(Class).select { |klass| klass < self }
48
+ end
49
+
50
+ # try to match string using @matcher_regexp
51
+ # return false if not matched
52
+ # return true if matched
53
+ # return match if matched and it should return something
54
+ def match(string)
55
+ match = @matcher_regexp.match(string)
56
+ if match.class == MatchData
57
+ if match.nil?
58
+ nil
59
+ else
60
+ caps = match.captures
61
+ if caps.length == 1
62
+ if caps.first.nil?
63
+ true
64
+ else
65
+ caps.first
66
+ end
67
+ else
68
+ caps
69
+ end
70
+ end
71
+ else
72
+ false
73
+ end
74
+ end
75
+
76
+ end
77
+ end # class << self
78
+ end
@@ -0,0 +1,10 @@
1
+ module Memelicious
2
+ class BearGryllis < Meme
3
+ matcher /(.*) better drink my own piss/i
4
+
5
+ should_match "write a ruby library. better drink my own piss"
6
+ and_return "write a ruby library."
7
+
8
+ should_not_match "blah blah blah"
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module Memelicious
2
+ class BuzzLightyear < Meme
3
+ matcher /(?<string>.*)[,\.\n\s](\s*)\k<string> everywhere/i
4
+
5
+ should_match "regular expressions. regular expressions everywhere"
6
+ and_return 'regular expressions'
7
+
8
+ should_match "regular expressions, regular expressions everywhere"
9
+ and_return 'regular expressions'
10
+
11
+ should_match "regular expressions\nregular expressions everywhere"
12
+ and_return 'regular expressions'
13
+
14
+ should_not_match "regular expressions, sandwiches everywhere"
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module Memelicious
2
+ class DarthVader < Meme
3
+ matcher /I find your lack of (.*) disturbing/i
4
+
5
+ should_match "I find your lack of tests disturbing"
6
+ and_return "tests"
7
+
8
+ should_not_match "I find sandwiches disturbing"
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class DosEquis < Meme
3
+ matcher /I don'?t always (.*) but when I do (.*)/i
4
+
5
+ should_match "I don't always write ruby libraries but when I do they're stupid"
6
+ and_return ["write ruby libraries", "they're stupid"]
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class ForTheGod < Meme
3
+ matcher /(.*) for the (.*) god/i
4
+
5
+ should_match "memes for the meme god"
6
+ and_return ["memes", "meme"]
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class Fry < Meme
3
+ matcher /(can'?t tell|not sure) if (.+) or (.+)/i
4
+
5
+ should_match 'not sure if test passing or spec broken'
6
+ and_return ["not sure", "test passing", "spec broken"]
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class HipsterKitty < Meme
3
+ matcher /I liked (.*) before (.*)/i
4
+
5
+ should_match 'I liked the concept of memes before the word was borrowed from Dawkins\' "The Selfish Gene" for use by the reddit community'
6
+ and_return ["the concept of memes", "the word was borrowed from Dawkins' \"The Selfish Gene\" for use by the reddit community"]
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class ICanHaz < Meme
3
+ matcher /I can ha[zs] (.*)/i
4
+
5
+ should_match "I can has regular expressions?"
6
+ and_return "regular expressions?"
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Memelicious
2
+ class IsBest < Meme
3
+ matcher /(\w+\b) (?<string>\w+\b) is best (\k<string>)/i
4
+
5
+ should_match "North Korea is best Korea"
6
+ and_return "Korea"
7
+
8
+ should_not_match "North Korea is best country"
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class JimmyMcMillan < Meme
3
+ matcher /(.*) is too damn high!/i
4
+
5
+ should_match "the time I spend on stupid programming projects is too damn high!"
6
+ and_return "the time I spend on stupid programming projects"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class Patrick < Meme
3
+ matcher /let'?s take all the (.*) and (.*)/
4
+
5
+ should_match 'lets take all the memes and encode them as regular expressions'
6
+ and_return ['memes', 'encode them as regular expressions']
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class Pokemon < Meme
3
+ matcher /a wild (.+) appears/i
4
+
5
+ should_match "A wild ruby library appears"
6
+ and_return "ruby library"
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class SeanBean < Meme
3
+ matcher /Prepare yourself,? (.*) are coming/i
4
+
5
+ should_match "prepare yourself, the automatically generated memes are coming"
6
+ and_return "the automatically generated memes"
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ module Memelicious
2
+ class Soon < Meme
3
+ matcher /^soon(\.|\.{3})?$/i
4
+
5
+ should_match "soon"
6
+ and_return true
7
+ should_match "soon."
8
+ and_return '.'
9
+ should_match "soon..."
10
+ and_return '...'
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Memelicious
2
+ class SovietRussia < Meme
3
+ matcher /in soviet russia,? (.*) you!?/i
4
+
5
+ should_match 'in soviet russia, regular expressions match you'
6
+ and_return 'regular expressions match'
7
+
8
+ should_match 'in soviet russia, sentence exclaims you!'
9
+ and_return 'sentence exclaims'
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Memelicious
2
+ class YUNo < Meme
3
+ matcher /Y U No (.+)\?/i
4
+
5
+ should_match 'y u no write test generators instead of writing all rspecs manually?'
6
+ and_return 'write test generators instead of writing all rspecs manually'
7
+
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Memelicious
2
+ class YoDawg < Meme
3
+ matcher /yo dawg I hea?rd you like (.*) so I put a (.*) in your (.*) so you can (.*) while you (.*)/i
4
+
5
+ should_match 'yo dawg I heard you like X so I put a X in your X so you can X while you X'
6
+ and_return %w{X X X X X}
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memelicious
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Austin G. Davis-Richardson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Identify and parse internet "memes" in Ruby.
14
+ email: harekrishna@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/memelicious.rb
20
+ - lib/memelicious/matcher.rb
21
+ - lib/memelicious/meme.rb
22
+ - lib/memelicious/memes/bear_gryllis.rb
23
+ - lib/memelicious/memes/buzzlightyear.rb
24
+ - lib/memelicious/memes/darth_vader.rb
25
+ - lib/memelicious/memes/dos_equis.rb
26
+ - lib/memelicious/memes/for_the_god.rb
27
+ - lib/memelicious/memes/fry.rb
28
+ - lib/memelicious/memes/hipster_kitty.rb
29
+ - lib/memelicious/memes/i_can_haz.rb
30
+ - lib/memelicious/memes/is_best.rb
31
+ - lib/memelicious/memes/jimmy_mcmillan.rb
32
+ - lib/memelicious/memes/patrick.rb
33
+ - lib/memelicious/memes/pokemon.rb
34
+ - lib/memelicious/memes/sean_bean.rb
35
+ - lib/memelicious/memes/soon.rb
36
+ - lib/memelicious/memes/soviet_russia.rb
37
+ - lib/memelicious/memes/y_u_no.rb
38
+ - lib/memelicious/memes/yo_dawg.rb
39
+ homepage: https://github.com/audy/memelicious
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.4.5
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Identify and parse internet "memes" in Ruby.
63
+ test_files: []