2012-04-12 09:49:23 -07:00
|
|
|
package DDG::Goodie::AspectRatio;
|
2012-04-14 04:51:03 -07:00
|
|
|
# ABSTRACT: Calculates aspect ratio based on previously defined one
|
2012-04-12 09:49:23 -07:00
|
|
|
|
|
|
|
use DDG::Goodie;
|
|
|
|
|
2012-05-23 19:05:08 -07:00
|
|
|
triggers start => "aspect ratio";
|
2012-04-12 09:49:23 -07:00
|
|
|
|
|
|
|
zci is_cached => 1;
|
|
|
|
zci answer_type => "aspect_ratio";
|
|
|
|
|
2012-05-23 19:05:08 -07:00
|
|
|
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;
|