2012-03-01 07:59:31 -08:00
|
|
|
package DDG::Goodie::EmToPx;
|
|
|
|
|
|
|
|
use DDG::Goodie;
|
|
|
|
|
2012-05-23 19:05:08 -07:00
|
|
|
triggers any => "em", "px";
|
|
|
|
|
2012-03-01 07:59:31 -08:00
|
|
|
zci is_cached => 1;
|
2012-03-20 21:08:12 -07:00
|
|
|
zci answer_type => "conversion";
|
2012-03-01 07:59:31 -08:00
|
|
|
|
2012-11-06 13:17:59 -08:00
|
|
|
primary_example_queries '10 px to em';
|
|
|
|
secondary_example_queries '12.2 px in em assuming a 12.2 font size';
|
|
|
|
description 'convert from px to em';
|
|
|
|
name 'EmToPx';
|
|
|
|
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/EmToPx.pm';
|
|
|
|
category 'conversions';
|
|
|
|
topics 'programming';
|
|
|
|
attribution twitter => 'crazedpsyc',
|
|
|
|
cpan => 'CRZEDPSYC' ;
|
|
|
|
|
2012-05-02 16:24:12 -07:00
|
|
|
handle query_raw => sub {
|
2012-05-03 07:30:06 -07:00
|
|
|
s/(?![\.\s])\W//g;
|
|
|
|
return unless /^(?:convert|change|what\s*(?:s|is|are)\s+)?(\d+\.\d*|\d*\.\d+|\d+)\s*(em|px)\s+(?:in|to)\s+(em|px)(?:\s+(?:with|at|using|assuming)(?:\s+an?)?\s+(\d+\.\d*|\d*\.\d+|\d+)\s*px)?/i;
|
2012-05-02 16:24:12 -07:00
|
|
|
my $target = lc($3);
|
|
|
|
my $num = $1;
|
|
|
|
my $source = lc($2);
|
2012-03-01 07:59:31 -08:00
|
|
|
|
2012-05-02 16:24:12 -07:00
|
|
|
my $fontsize = ( defined $4 ) ? $4 : 16;
|
2012-03-01 07:59:31 -08:00
|
|
|
|
|
|
|
my $result;
|
2012-05-02 16:24:12 -07:00
|
|
|
$result = $num * $fontsize if $target eq 'px' && $source eq 'em';
|
|
|
|
$result = $num / $fontsize if $target eq 'em' && $source eq 'px';
|
|
|
|
my $plur = $result == 1 ? "is" : "are";
|
2012-03-01 07:59:31 -08:00
|
|
|
|
2012-05-02 16:24:12 -07:00
|
|
|
return "There $plur $result $target in $num $source (assuming a ${fontsize}px font size)";
|
2012-03-01 07:59:31 -08:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
1;
|