ColorPicker: Makes triggering more generic (#4138)
* ColorPicker: Remove suffixed triggers * ColorPicker: Handle extra words in remainder * ColorPicker: Adds tests to check extra words in query * ColorPicker: Add 'conversion' to remove from query * ColorPicker: Add test for 'conversion' keyword in remainder * ColorPicker: Simplify regex, lowercase query * ColorPicker: Remove print statementsmaster
parent
512d0c49e8
commit
c3595bdea0
|
@ -3,6 +3,7 @@ package DDG::Goodie::ColorPicker;
|
|||
|
||||
use DDG::Goodie;
|
||||
use Color::Library;
|
||||
use Text::Trim;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
@ -14,8 +15,11 @@ triggers start => share("triggers.txt")->slurp;
|
|||
|
||||
my $goodie_version = $DDG::GoodieBundle::OpenSourceDuckDuckGo::VERSION // 999;
|
||||
|
||||
handle remainder => sub {
|
||||
handle remainder_lc => sub {
|
||||
s/converter|conversion|colou?r//g;
|
||||
|
||||
my $remainder = $_;
|
||||
trim($remainder);
|
||||
my $color = undef;
|
||||
my $path = "/share/goodie/color_picker/$goodie_version/";
|
||||
if ($remainder =~ /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/) {
|
||||
|
|
|
@ -3,26 +3,14 @@ colour picker
|
|||
colorpicker
|
||||
colourpicker
|
||||
rgb to hex
|
||||
rgb to hex converter
|
||||
rgb to hsv
|
||||
rgb to hsv converter
|
||||
rgb to cmyk
|
||||
rgb to cmyk converter
|
||||
hex to rgb
|
||||
hex to rgb converter
|
||||
hex to hsv
|
||||
hex to hsv converter
|
||||
hex to cmyk
|
||||
hex to cmyk converter
|
||||
hsv to rgb
|
||||
hsv to rgb converter
|
||||
hsv to hex
|
||||
hsv to hex converter
|
||||
hsv to cmyk
|
||||
hsv to cmyk converter
|
||||
cmyk to rgb
|
||||
cmyk to rgb converter
|
||||
cmyk to hex
|
||||
cmyk to hex converter
|
||||
cmyk to hsv
|
||||
cmyk to hsv converter
|
||||
|
|
118
t/ColorPicker.t
118
t/ColorPicker.t
|
@ -45,28 +45,40 @@ ddg_goodie_test(
|
|||
'colour picker' => build_test(undef),
|
||||
'rgb to hex' => build_test(undef),
|
||||
'rgb to hex converter' => build_test(undef),
|
||||
'rgb to hex conversion' => build_test(undef),
|
||||
'rgb to hsv' => build_test(undef),
|
||||
'rgb to hsv converter' => build_test(undef),
|
||||
'rgb to hsv conversion' => build_test(undef),
|
||||
'rgb to cmyk' => build_test(undef),
|
||||
'rgb to cmyk converter' => build_test(undef),
|
||||
'rgb to cmyk conversion' => build_test(undef),
|
||||
'hex to rgb' => build_test(undef),
|
||||
'hex to rgb converter' => build_test(undef),
|
||||
'hex to rgb conversion' => build_test(undef),
|
||||
'hex to hsv' => build_test(undef),
|
||||
'hex to hsv converter' => build_test(undef),
|
||||
'hex to hsv conversion' => build_test(undef),
|
||||
'hex to cmyk' => build_test(undef),
|
||||
'hex to cmyk converter' => build_test(undef),
|
||||
'hex to cmyk conversion' => build_test(undef),
|
||||
'hsv to rgb' => build_test(undef),
|
||||
'hsv to rgb converter' => build_test(undef),
|
||||
'hsv to rgb conversion' => build_test(undef),
|
||||
'hsv to hex' => build_test(undef),
|
||||
'hsv to hex converter' => build_test(undef),
|
||||
'hsv to hex conversion' => build_test(undef),
|
||||
'hsv to cmyk' => build_test(undef),
|
||||
'hsv to cmyk converter' => build_test(undef),
|
||||
'hsv to cmyk conversion' => build_test(undef),
|
||||
'cmyk to rgb' => build_test(undef),
|
||||
'cmyk to rgb converter' => build_test(undef),
|
||||
'cmyk to rgb conversion' => build_test(undef),
|
||||
'cmyk to hex' => build_test(undef),
|
||||
'cmyk to hex converter' => build_test(undef),
|
||||
'cmyk to hex conversion' => build_test(undef),
|
||||
'cmyk to hsv' => build_test(undef),
|
||||
'cmyk to hsv converter' => build_test(undef),
|
||||
'cmyk to hsv conversion' => build_test(undef),
|
||||
|
||||
# Testing Hex Color Codes Full
|
||||
'colorpicker #474747' => build_test('#474747'),
|
||||
|
@ -75,10 +87,32 @@ ddg_goodie_test(
|
|||
'colour picker #474747' => build_test('#474747'),
|
||||
'hex to rgb #474747' => build_test('#474747'),
|
||||
'hex to rgb converter #474747' => build_test('#474747'),
|
||||
'hex to rgb #474747 converter' => build_test('#474747'),
|
||||
'hex to hsv #474747' => build_test('#474747'),
|
||||
'hex to hsv converter #474747' => build_test('#474747'),
|
||||
'hex to hsv #474747 converter' => build_test('#474747'),
|
||||
'hex to cmyk #474747' => build_test('#474747'),
|
||||
'hex to cmyk converter #474747' => build_test('#474747'),
|
||||
'hex to cmyk #474747 converter' => build_test('#474747'),
|
||||
'hex to rgb color #474747' => build_test('#474747'),
|
||||
'hex to rgb colour #474747' => build_test('#474747'),
|
||||
'hex to hsv color #474747' => build_test('#474747'),
|
||||
'hex to hsv colour #474747' => build_test('#474747'),
|
||||
'hex to cmyk color #474747' => build_test('#474747'),
|
||||
'hex to cmyk colour #474747' => build_test('#474747'),
|
||||
'hex to rgb #474747 color' => build_test('#474747'),
|
||||
'hex to rgb #474747 colour' => build_test('#474747'),
|
||||
'hex to hsv #474747 color' => build_test('#474747'),
|
||||
'hex to hsv #474747 colour' => build_test('#474747'),
|
||||
'hex to cmyk #474747 color' => build_test('#474747'),
|
||||
'hex to cmyk #474747 colour' => build_test('#474747'),
|
||||
'hex to rgb conversion #474747' => build_test('#474747'),
|
||||
'hex to rgb #474747 conversion' => build_test('#474747'),
|
||||
'hex to hsv conversion #474747' => build_test('#474747'),
|
||||
'hex to hsv #474747 conversion' => build_test('#474747'),
|
||||
'hex to cmyk #474747' => build_test('#474747'),
|
||||
'hex to cmyk conversion #474747' => build_test('#474747'),
|
||||
'hex to cmyk #474747 conversion' => build_test('#474747'),
|
||||
|
||||
# Testing Hex Color Shorthand
|
||||
'colorpicker #474' => build_test('#474'),
|
||||
|
@ -87,10 +121,31 @@ ddg_goodie_test(
|
|||
'colour picker #474' => build_test('#474'),
|
||||
'hex to rgb #474' => build_test('#474'),
|
||||
'hex to rgb converter #474' => build_test('#474'),
|
||||
'hex to rgb #474 converter' => build_test('#474'),
|
||||
'hex to hsv #474' => build_test('#474'),
|
||||
'hex to hsv converter #474' => build_test('#474'),
|
||||
'hex to hsv #474 converter' => build_test('#474'),
|
||||
'hex to cmyk #474' => build_test('#474'),
|
||||
'hex to cmyk converter #474' => build_test('#474'),
|
||||
'hex to cmyk #474 converter' => build_test('#474'),
|
||||
'hex to rgb color #474' => build_test('#474'),
|
||||
'hex to rgb colour #474' => build_test('#474'),
|
||||
'hex to hsv color #474' => build_test('#474'),
|
||||
'hex to hsv colour #474' => build_test('#474'),
|
||||
'hex to cmyk color #474' => build_test('#474'),
|
||||
'hex to cmyk colour #474' => build_test('#474'),
|
||||
'hex to rgb #474 color' => build_test('#474'),
|
||||
'hex to rgb #474 colour' => build_test('#474'),
|
||||
'hex to hsv #474 color' => build_test('#474'),
|
||||
'hex to hsv #474 colour' => build_test('#474'),
|
||||
'hex to cmyk #474 color' => build_test('#474'),
|
||||
'hex to cmyk #474 colour' => build_test('#474'),
|
||||
'hex to rgb conversion #474' => build_test('#474'),
|
||||
'hex to rgb #474 conversion' => build_test('#474'),
|
||||
'hex to hsv conversion #474' => build_test('#474'),
|
||||
'hex to hsv #474 conversion' => build_test('#474'),
|
||||
'hex to cmyk conversion #474' => build_test('#474'),
|
||||
'hex to cmyk #474 conversion' => build_test('#474'),
|
||||
|
||||
# Testing RGB
|
||||
'colorpicker rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
|
@ -99,10 +154,31 @@ ddg_goodie_test(
|
|||
'colour picker rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex converter rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex rgb(240,100,141) converter' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv converter rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv rgb(240,100,141) converter' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk converter rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk rgb(240,100,141) converter' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex color rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex colour rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv color rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv colour rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk color rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk colour rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex rgb(240,100,141) color' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex rgb(240,100,141) colour' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv rgb(240,100,141) color' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv rgb(240,100,141) colour' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk rgb(240,100,141) color' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk rgb(240,100,141) colour' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex conversion rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hex rgb(240,100,141) conversion' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv conversion rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to hsv rgb(240,100,141) conversion' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk conversion rgb(240,100,141)' => build_test('rgb,240,100,141'),
|
||||
'rgb to cmyk rgb(240,100,141) conversion' => build_test('rgb,240,100,141'),
|
||||
|
||||
# Testing HSV
|
||||
'colorpicker hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
|
@ -111,10 +187,31 @@ ddg_goodie_test(
|
|||
'colour picker hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb converter hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb hsv(50,40,30) converter' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex converter hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex hsv(50,40,30) converter' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk converter hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk hsv(50,40,30) converter' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb color hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb colour hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex color hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex colour hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk color hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk colour hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb hsv(50,40,30) color' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb hsv(50,40,30) colour' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex hsv(50,40,30) color' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex hsv(50,40,30) colour' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk hsv(50,40,30) color' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk hsv(50,40,30) colour' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb conversion hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to rgb hsv(50,40,30) conversion' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex conversion hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to hex hsv(50,40,30) conversion' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk conversion hsv(50,40,30)' => build_test('hsv,50,40,30'),
|
||||
'hsv to cmyk hsv(50,40,30) conversion' => build_test('hsv,50,40,30'),
|
||||
|
||||
# Testing CMYK
|
||||
'colorpicker cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
|
@ -123,10 +220,31 @@ ddg_goodie_test(
|
|||
'colour picker cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb converter cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb cmyk(50,40,30,20) converter' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex converter cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex cmyk(50,40,30,20) converter' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv converter cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv cmyk(50,40,30,20) converter' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb color cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb colour cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex color cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex colour cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv color cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv colour cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb cmyk(50,40,30,20) color' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb cmyk(50,40,30,20) colour' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex cmyk(50,40,30,20) color' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex cmyk(50,40,30,20) colour' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv cmyk(50,40,30,20) color' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv cmyk(50,40,30,20) colour' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb conversion cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to rgb cmyk(50,40,30,20) conversion' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex conversion cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hex cmyk(50,40,30,20) conversion' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv conversion cmyk(50,40,30,20)' => build_test('cmyk,50,40,30,20'),
|
||||
'cmyk to hsv cmyk(50,40,30,20) conversion' => build_test('cmyk,50,40,30,20'),
|
||||
|
||||
# Queries to ignore.
|
||||
'hello there colorpicker' => undef,
|
||||
|
|
Loading…
Reference in New Issue