/lib/DDG/Spice/Drinks.pm
Perl | 30 lines | 21 code | 7 blank | 2 comment | 1 complexity | 463aad66b1c6ad3c32d956104375764a MD5 | raw file
Possible License(s): Apache-2.0
- package DDG::Spice::Drinks;
- # ABSTRACT: Drink mixing instructions
- use strict;
- use DDG::Spice;
- use Text::Trim;
- spice is_cached => 1;
- spice to => 'http://www.thecocktaildb.com/api/json/v1/{{ENV{DDG_SPICE_COCKTAILDB_APIKEY}}}/search.php?s=$1';
- spice wrap_jsonp_callback => 1;
- triggers any => ('cocktail', 'drink', 'ingredient', 'ingredients', 'make', 'making', 'mix', 'mixing', 'recipe');
- my %drinks = map { trim($_) => 0 } share('drinks.txt')->slurp;
- my @stop_words = ("are", "being", "for", "how", "is", "needed", "that", "to", "used", "what", "within");
- my ($rx) = map qr/(?:$_)/, join "|", map qr/\b\Q$_\E\b/, @stop_words;
- # Handle statement
- handle remainder_lc => sub {
- $_ =~ s/$rx//g;
- $_ =~ s/\b(a|an|in|of)\b//;
- trim $_;
- if (exists ($drinks{$_})) {
- return $_;
- }
- return;
- };
- 1;