2015-04-06 07:07:54 -07:00
|
|
|
package DDG::Goodie::Constants;
|
|
|
|
# ABSTRACT: Various Math and Physics constants.
|
2016-04-10 11:19:36 -07:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2015-04-06 07:07:54 -07:00
|
|
|
use DDG::Goodie;
|
2015-08-08 01:08:59 -07:00
|
|
|
use YAML::XS qw( LoadFile );
|
2015-04-06 07:07:54 -07:00
|
|
|
|
|
|
|
zci answer_type => "constants";
|
|
|
|
zci is_cached => 1;
|
|
|
|
|
2016-02-23 08:20:37 -08:00
|
|
|
my $constants = LoadFile(share("constants.yml"));
|
2015-04-06 07:07:54 -07:00
|
|
|
|
2015-10-20 02:17:24 -07:00
|
|
|
#loop through constants
|
|
|
|
foreach my $name (keys %$constants) {
|
|
|
|
#obtain to constant with name $keyword
|
|
|
|
my $constant = $constants->{$name};
|
2015-12-13 03:55:53 -08:00
|
|
|
|
2015-10-20 02:17:24 -07:00
|
|
|
#add aliases as separate triggers
|
|
|
|
foreach my $alias (@{$constant->{'aliases'}}) {
|
|
|
|
$constants->{$alias} = $constant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my @triggers = keys %{$constants};
|
2015-08-08 01:08:59 -07:00
|
|
|
triggers startend => @triggers;
|
2015-04-06 07:07:54 -07:00
|
|
|
|
|
|
|
# Handle statement
|
2015-08-08 01:08:59 -07:00
|
|
|
handle query_lc => sub {
|
2015-10-20 02:17:24 -07:00
|
|
|
my $constant = $constants->{$_};
|
|
|
|
return unless my $val = $constant->{'value'};
|
2015-12-13 03:55:53 -08:00
|
|
|
|
2015-10-20 02:17:24 -07:00
|
|
|
#fallback to plain answer if html is not present
|
|
|
|
my $result = $val->{'html'} ? $val->{'html'} : $val->{'plain'};
|
2015-08-08 01:08:59 -07:00
|
|
|
|
2015-10-20 02:17:24 -07:00
|
|
|
return $result, structured_answer => {
|
2016-05-14 12:21:54 -07:00
|
|
|
data => {
|
|
|
|
title => $result,
|
|
|
|
subtitle => $constant->{'name'}
|
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => 'text',
|
|
|
|
},
|
|
|
|
meta => {
|
2016-04-28 10:40:57 -07:00
|
|
|
signal => 'high'
|
|
|
|
}
|
2015-08-08 01:08:59 -07:00
|
|
|
};
|
2015-04-06 07:07:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
1;
|