BirthStone: use structured answer
parent
74e0d2576c
commit
0015806d70
|
@ -5,8 +5,8 @@ use DDG::Goodie;
|
|||
|
||||
triggers startend => 'birthstone', 'birth stone';
|
||||
|
||||
zci answer_type => "BirthStone";
|
||||
zci is_cached => 1;
|
||||
zci answer_type => "birth_stone";
|
||||
zci is_cached => 1;
|
||||
|
||||
primary_example_queries 'birthstone april';
|
||||
secondary_example_queries 'may birth stone';
|
||||
|
@ -14,28 +14,36 @@ description 'returns the birth stone of the specified month';
|
|||
name 'BirthStone';
|
||||
topics 'special_interest', 'entertainment';
|
||||
category 'random';
|
||||
attribution github => [ 'https://github.com/austinheimark', 'austin_heimark' ];
|
||||
attribution github => ['https://github.com/austinheimark', 'austin_heimark'];
|
||||
|
||||
my %birthstones = (
|
||||
"january" => "Garnet",
|
||||
"february" => "Amethyst",
|
||||
"march" => "Aquamarine",
|
||||
"april" => "Diamond",
|
||||
"may" => "Emerald",
|
||||
"june" => "Pearl",
|
||||
"july" => "Ruby",
|
||||
"august" => "Peridot",
|
||||
"september" => "Sapphire",
|
||||
"october" => "Opal",
|
||||
"november" => "Topaz",
|
||||
"december" => "Turquoise"
|
||||
"January" => "Garnet",
|
||||
"February" => "Amethyst",
|
||||
"March" => "Aquamarine",
|
||||
"April" => "Diamond",
|
||||
"May" => "Emerald",
|
||||
"June" => "Pearl",
|
||||
"July" => "Ruby",
|
||||
"August" => "Peridot",
|
||||
"September" => "Sapphire",
|
||||
"October" => "Opal",
|
||||
"November" => "Topaz",
|
||||
"December" => "Turquoise"
|
||||
);
|
||||
|
||||
handle remainder => sub {
|
||||
my $month = lc $_;
|
||||
my $stone = $birthstones{$month};
|
||||
return ucfirst $month . " birthstone: $stone" if $stone;
|
||||
return;
|
||||
my $month = ucfirst lc $_;
|
||||
|
||||
return unless $month;
|
||||
my $stone = $birthstones{$month};
|
||||
return unless $stone;
|
||||
|
||||
return $month . " birthstone: $stone",
|
||||
structured_answer => {
|
||||
input => [$month],
|
||||
operation => 'birthstone',
|
||||
result => $stone
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
@ -5,18 +5,51 @@ use warnings;
|
|||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
zci answer_type => "BirthStone";
|
||||
zci is_cached => 1;
|
||||
zci answer_type => "birth_stone";
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(
|
||||
DDG::Goodie::BirthStone
|
||||
)],
|
||||
'april birth stone' => test_zci('April birthstone: Diamond'),
|
||||
'birthstone JUNE' => test_zci('June birthstone: Pearl'),
|
||||
'DecEmber birthstone' => test_zci('December birthstone: Turquoise'),
|
||||
'birthstone april' => test_zci('April birthstone: Diamond'),
|
||||
'may birth stone' => test_zci('May birthstone: Emerald'),
|
||||
[qw( DDG::Goodie::BirthStone )],
|
||||
'april birth stone' => test_zci(
|
||||
'April birthstone: Diamond',
|
||||
structured_answer => {
|
||||
input => ['April'],
|
||||
operation => 'birthstone',
|
||||
result => 'Diamond'
|
||||
}
|
||||
),
|
||||
'birthstone JUNE' => test_zci(
|
||||
'June birthstone: Pearl',
|
||||
structured_answer => {
|
||||
input => ['June'],
|
||||
operation => 'birthstone',
|
||||
result => 'Pearl'
|
||||
}
|
||||
),
|
||||
'DecEmber birthstone' => test_zci(
|
||||
'December birthstone: Turquoise',
|
||||
structured_answer => {
|
||||
input => ['December'],
|
||||
operation => 'birthstone',
|
||||
result => 'Turquoise'
|
||||
}
|
||||
),
|
||||
'birthstone april' => test_zci(
|
||||
'April birthstone: Diamond',
|
||||
structured_answer => {
|
||||
input => ['April'],
|
||||
operation => 'birthstone',
|
||||
result => 'Diamond'
|
||||
}
|
||||
),
|
||||
'may birth stone' => test_zci(
|
||||
'May birthstone: Emerald',
|
||||
structured_answer => {
|
||||
input => ['May'],
|
||||
operation => 'birthstone',
|
||||
result => 'Emerald'
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue