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
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
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-11-06 15:50:37 -08:00
|
|
|
primary_example_queries 'aspect ratio 4:3 640:?';
|
|
|
|
description 'complete the missing value with a given ratio';
|
|
|
|
name 'AspectRatio';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/AspectRatio.pm';
|
|
|
|
category 'calculations';
|
|
|
|
topics 'math';
|
2015-01-07 10:37:42 -08:00
|
|
|
attribution github => [ 'https://github.com/mrshu', 'mrshu' ];
|
2012-11-06 15:50:37 -08:00
|
|
|
|
2012-05-23 19:05:08 -07:00
|
|
|
handle remainder => sub {
|
2014-10-05 23:55:08 -07:00
|
|
|
my $input = $_;
|
2012-04-12 09:49:23 -07:00
|
|
|
my $result = 0;
|
2014-10-05 23:55:08 -07:00
|
|
|
my $ratio = 0;
|
2012-04-12 09:49:23 -07:00
|
|
|
|
2014-10-05 23:55:08 -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;
|
2014-10-05 23:55:08 -07:00
|
|
|
my $pretty_ratio = $1 . ':' . $2;
|
2012-04-12 09:49:23 -07:00
|
|
|
|
2014-10-05 23:55:08 -07:00
|
|
|
my $result;
|
2012-04-12 09:49:23 -07:00
|
|
|
if ($6 && $6 eq "?") {
|
2014-10-05 23:55:08 -07:00
|
|
|
$result = $5 . ':' . ($5 / $ratio);
|
2012-04-12 09:49:23 -07:00
|
|
|
} elsif ($3 && $3 eq "?") {
|
2014-10-05 23:55:08 -07:00
|
|
|
$result = ($4 * $ratio) . ':' . $4;
|
2012-04-12 09:49:23 -07:00
|
|
|
}
|
2014-10-05 23:55:08 -07:00
|
|
|
return unless $result;
|
|
|
|
|
|
|
|
return "Aspect ratio: $result ($pretty_ratio)",
|
|
|
|
structured_answer => {
|
|
|
|
input => [$pretty_ratio],
|
2015-01-08 23:52:22 -08:00
|
|
|
operation => 'Aspect ratio',
|
2014-10-05 23:55:08 -07:00
|
|
|
result => $result
|
|
|
|
};
|
2012-04-12 09:49:23 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
1;
|