Sha256: 1b72ff067913bb310c20623ad53d2fddeff7bbc05fc7bf131313a0ba11412ddc
Contents?: true
Size: 767 Bytes
Versions: 3
Compression:
Stored size: 767 Bytes
Contents
require File.join(File.dirname(__FILE__), 'memes') module Memetron class Matcher # Attempt to identify the meme in a string. def match(string) first_match = MEMES.detect { |meme, regexp| string =~ regexp } if first_match.nil? nil else meme_name(first_match) end end # Return variable regions of meme def parse(meme, string) MEMES[meme].match(string).to_a[1..-1] end # Match and parse a meme #=> [:meme_name, ['parsed', 'meme', 'bits']] def match_and_parse(string) meme = match(string) if meme.nil? return meme end bits = parse(meme, string) [meme, bits] end private def meme_name(meme_pair) meme_pair[0] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
memetron-0.1.3 | lib/memetron/matcher.rb |
memetron-0.1.2 | lib/memetron/matcher.rb |
memetron-0.1.1 | lib/memetron/matcher.rb |