zeroclickinfo-goodies/lib/DDG/Goodie/AspectRatio.pm

31 lines
738 B
Perl
Raw Normal View History

2012-04-12 09:49:23 -07:00
package DDG::Goodie::AspectRatio;
# ABSTRACT: Calculates aspect ratio based on previously defined one
2012-04-12 09:49:23 -07:00
use DDG::Goodie;
triggers start => "aspect ratio";
2012-04-12 09:49:23 -07:00
zci is_cached => 1;
zci answer_type => "aspect_ratio";
handle remainder => sub {
my $input = $_;
2012-04-12 09:49:23 -07:00
my $result = 0;
my $ratio = 0;
2012-04-14 06:15:53 -07:00
if ($input =~ /^(\d+(?:\.\d+)?)\s*\:\s*(\d+(?:\.\d+)?)\s*(?:(?:(\?)\s*:\s*(\d+(?:\.\d+)?))|(?:(\d+(?:\.\d+)?)\s*:\s*(\?)))$/){
2012-04-12 09:49:23 -07:00
$ratio = $1 / $2;
if ($6 && $6 eq "?") {
$result = $5 / $ratio;
2012-04-14 06:15:53 -07:00
return "Aspect ratio: $5:$result ($1:$2)";
2012-04-12 09:49:23 -07:00
} elsif ($3 && $3 eq "?") {
$result = $4 * $ratio;
2012-04-14 06:15:53 -07:00
return "Aspect ratio: $result:$4 ($1:$2)";
2012-04-12 09:49:23 -07:00
}
}
return;
};
1;