memelicious 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/memelicious.rb +9 -0
- data/lib/memelicious/matcher.rb +20 -0
- data/lib/memelicious/meme.rb +78 -0
- data/lib/memelicious/memes/bear_gryllis.rb +10 -0
- data/lib/memelicious/memes/buzzlightyear.rb +16 -0
- data/lib/memelicious/memes/darth_vader.rb +10 -0
- data/lib/memelicious/memes/dos_equis.rb +8 -0
- data/lib/memelicious/memes/for_the_god.rb +8 -0
- data/lib/memelicious/memes/fry.rb +8 -0
- data/lib/memelicious/memes/hipster_kitty.rb +8 -0
- data/lib/memelicious/memes/i_can_haz.rb +8 -0
- data/lib/memelicious/memes/is_best.rb +10 -0
- data/lib/memelicious/memes/jimmy_mcmillan.rb +8 -0
- data/lib/memelicious/memes/patrick.rb +8 -0
- data/lib/memelicious/memes/pokemon.rb +8 -0
- data/lib/memelicious/memes/sean_bean.rb +8 -0
- data/lib/memelicious/memes/soon.rb +12 -0
- data/lib/memelicious/memes/soviet_russia.rb +11 -0
- data/lib/memelicious/memes/y_u_no.rb +9 -0
- data/lib/memelicious/memes/yo_dawg.rb +8 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -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
|
data/lib/memelicious.rb
ADDED
@@ -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,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,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,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,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: []
|