| 1 | # Standard and Poors web links. | ||
| 2 | |||
| 3 | # Copyright 2007, 2008, 2009, 2010, 2016 Kevin Ryde | ||
| 4 | |||
| 5 | # This file is part of Chart. | ||
| 6 | # | ||
| 7 | # Chart is free software; you can redistribute it and/or modify it under | ||
| 8 | # the terms of the GNU General Public License as published by the Free | ||
| 9 | # Software Foundation; either version 3, or (at your option) any later | ||
| 10 | # version. | ||
| 11 | # | ||
| 12 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 15 | # details. | ||
| 16 | # | ||
| 17 | # You should have received a copy of the GNU General Public License | ||
| 18 | # along with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | |||
| 21 | package App::Chart::Weblink::SandP; | ||
| 22 | use 5.008; | ||
| 23 | use strict; | ||
| 24 | use warnings; | ||
| 25 | use Carp; | ||
| 26 | use Locale::TextDomain ('App-Chart'); | ||
| 27 | |||
| 28 | use App::Chart::Glib::Ex::MoreUtils; | ||
| 29 | use App::Chart; | ||
| 30 | use base 'App::Chart::Weblink'; | ||
| 31 | |||
| 32 | sub new { | ||
| 33 | my ($class, %options) = @_; | ||
| 34 | my $symbol_table = $options{'symbol_table'} | ||
| 35 | || croak 'Missing symbol_table'; | ||
| 36 | |||
| 37 | # symbols with an entry in %$symbol_table, if not otherwise given | ||
| 38 | $options{'pred'} ||= App::Chart::Sympred::Proc->new | ||
| 39 | (sub { return exists $symbol_table->{$_[0]} }); | ||
| 40 | |||
| 41 | return $class->SUPER::new | ||
| 42 | (%options, | ||
| 43 | name => __('Standard and _Poors index information'), | ||
| 44 | desc => __('Open web browser at the Standard and Poors web site page for this index'), | ||
| 45 | proc => 'subclass'); | ||
| 46 | } | ||
| 47 | |||
| 48 | # language choices at page | ||
| 49 | # http://www2.standardandpoors.com/portal/site/sp/en/au/page.siteselection/site_selection/0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0.html | ||
| 50 | # the ones applied here are just those which follow the basic pattern | ||
| 51 | # | ||
| 52 | sub url { | ||
| 53 | my ($self, $symbol) = @_; | ||
| 54 | my $url = $self->{'url_pattern'}; | ||
| 55 | |||
| 56 | my $lang = App::Chart::Glib::Ex::MoreUtils::lang_select (en => 'en/us', | ||
| 57 | es => 'es/la', | ||
| 58 | pt => 'pt/la'); | ||
| 59 | $url =~ s/{lang}/$lang/; | ||
| 60 | |||
| 61 | $symbol = $self->{'symbol_table'}->{$symbol}; | ||
| 62 | $url =~ s/{symbol}/$symbol/; | ||
| 63 | |||
| 64 | return $url; | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; | ||
| 68 | __END__ | ||
| 69 | |||
| 70 | =for stopwords weblink Poors | ||
| 71 | |||
| 72 | =head1 NAME | ||
| 73 | |||
| 74 | App::Chart::Weblink::SandP -- web page links for symbols | ||
| 75 | |||
| 76 | =head1 SYNOPSIS | ||
| 77 | |||
| 78 | use App::Chart::Weblink::SandP; | ||
| 79 | App::Chart::Weblink::SandP->new (symbol_table => { '^GSPC' => '500' }, | ||
| 80 | url_pattern => '...{lang}...{symbol}'); | ||
| 81 | |||
| 82 | =head1 CLASS HIERARCHY | ||
| 83 | |||
| 84 | C<App::Chart::Weblink::SandP> is a subclass of C<App::Chart::Weblink>. | ||
| 85 | |||
| 86 | App::Chart::Weblink | ||
| 87 | App::Chart::Weblink::SandP | ||
| 88 | |||
| 89 | =head1 DESCRIPTION | ||
| 90 | |||
| 91 | An C<SandP> weblink goes to the Standard and Poors web site | ||
| 92 | |||
| 93 | =over 4 | ||
| 94 | |||
| 95 | L<http://www2.standardandpoors.com> | ||
| 96 | |||
| 97 | =back | ||
| 98 | |||
| 99 | with a table of symbols and a URL pattern for the link. The name and | ||
| 100 | description parts of the weblink are set automatically. Normally this is | ||
| 101 | just for indexes created or marketed by S&P. | ||
| 102 | |||
| 103 | =head1 FUNCTIONS | ||
| 104 | |||
| 105 | =over 4 | ||
| 106 | |||
| 107 | =item App::Chart::Weblink::SandP->new (symbol_table=>..., url_pattern=>...) | ||
| 108 | |||
| 109 | ... | ||
| 110 | |||
| 111 | =back | ||
| 112 | |||
| 113 | =head1 SEE ALSO | ||
| 114 | |||
| 115 | L<App::Chart::Weblink> | ||
| 116 | |||
| 117 | =cut |