class Memelicious::Meme
This class is inherited by memes and used to do the following
-
Define the meme using a regular expression
-
Define what the meme should match
-
Define what the meme should not match
-
Define what the meme should return
Attributes
negative_examples[RW]
positive_examples[RW]
Public Class Methods
and_return(example)
click to toggle source
this method defines what a meme should return use after calling Meme#should_match
For example
should_match
/this meme should match the following (.*)/ and return “what is captured by (.*)
# File lib/memelicious/meme.rb, line 42 def and_return(example) @positive_examples[@last_added] = example end
match(string)
click to toggle source
try to match string using @matcher_regexp return false if not matched return true if matched return match if matched and it should return something
# File lib/memelicious/meme.rb, line 54 def match(string) match = @matcher_regexp.match(string) if match.class == MatchData if match.nil? nil else caps = match.captures if caps.length == 1 if caps.first.nil? true else caps.first end else caps end end else false end end
matcher(matcher)
click to toggle source
# File lib/memelicious/meme.rb, line 18 def matcher(matcher) @matcher_regexp = matcher end
memes()
click to toggle source
# File lib/memelicious/meme.rb, line 46 def memes ObjectSpace.each_object(Class).select { |klass| klass < self } end
should_match(example)
click to toggle source
this method defines what a meme should match
# File lib/memelicious/meme.rb, line 23 def should_match(example) @positive_examples ||= Hash.new { |h, k| h[k] = nil } @positive_examples[example] = nil @last_added = example end
should_not_match(example)
click to toggle source
this method defines what a meme should not match
# File lib/memelicious/meme.rb, line 30 def should_not_match(example) @negative_examples ||= Array.new @negative_examples << example end