Update FlipText so it doesn't reverse with the "flip" trigger. Now it includes a "mirror" trigger which will flip and reverse it.

master
Robert Picard 2012-05-02 17:38:13 -04:00
parent 58b8900ca2
commit 0e04078a5e
3 changed files with 22 additions and 5 deletions

View File

@ -2,7 +2,7 @@ package DDG::Goodie::FlipText;
use DDG::Goodie;
triggers startend => "flip";
triggers startend => "flip", "mirror";
zci is_cached => 1;
zci answer_type => "flip_text";
@ -87,8 +87,19 @@ my %charMap = (
"<" => ">",
"_" => "\x{203E}");
handle remainder => sub {
my @string = split(//,reverse $_);
handle query => sub {
$_ =~ s/^(\s*flip\s*)//;
$_ =~ s/(\s*flip\s*)$//;
if ($_ =~ /^(\s*mirror\s*)/ || $_ =~ /(\s*mirror\s*)/) {
$_ =~ s/^(\s*mirror\s*)//;
$_ =~ s/(\s*mirror\s*)$//;
$_ = reverse $_;
}
my @string = split(//, $_);
my $flippedString;
for (@string) {
@ -103,6 +114,9 @@ handle remainder => sub {
$flippedString .= $_;
}
}
return $flippedString;
};

View File

@ -1,2 +1,4 @@
flip this_text right HerE.
This_text! Right here? flip
flip this text
this text flip
mirror this text
this text mirror

View File

@ -13,6 +13,7 @@ ddg_goodie_test(
DDG::Goodie::FlipText
)],
'flip test' => test_zci("\x{0287}\x{0073}\x{01DD}\x{0287}"),
'mirror test' => test_zci("\x{0287}\x{01DD}\x{0073}\x{0287}"),
);
done_testing;