Class: Memetron::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/memetron/matcher.rb

Instance Method Summary collapse

Instance Method Details

#match(string) ⇒ Object

Attempt to identify the meme in a string.



6
7
8
9
10
11
12
13
# File 'lib/memetron/matcher.rb', line 6

def match(string)
  first_match = MEMES.detect { |meme, regexp| string =~ regexp }
  if first_match.nil?
    nil
  else
    meme_name(first_match)
  end
end

#match_and_parse(string) ⇒ Object

Match and parse a meme

> [:meme_name, [‘parsed’, ‘meme’, ‘bits’]]



22
23
24
25
26
27
28
29
# File 'lib/memetron/matcher.rb', line 22

def match_and_parse(string)
  meme = match(string)
  if meme.nil?
    return meme
  end
  bits = parse(meme, string)
  [meme, bits]
end

#parse(meme, string) ⇒ Object

Return variable regions of meme



16
17
18
# File 'lib/memetron/matcher.rb', line 16

def parse(meme, string)
  MEMES[meme].match(string).to_a[1..-1]
end