Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9df9b3fc

Von Jan Büren vor fast 2 Jahren hinzugefügt

  • ID 9df9b3fc9ca0a31c4c634d1c5b61e7c144187f1c
  • Vorgänger 82017e3f
  • Nachfolger 068d65bc

vergessene Base-Class für UpdateExchangerates

Unterschiede anzeigen:

SL/BackgroundJob/UpdateExchangerates/Base.pm
1
package SL::BackgroundJob::UpdateExchangerates::Base;
2

  
3
use strict;
4

  
5
use parent qw(Rose::Object);
6

  
7
use Rose::Object::MakeMethods::Generic (
8
  scalar => [ qw(options) ],
9
);
10

  
11
sub update_rates {
12
  my ($self, $rates) = @_;
13
  die 'needs to be overwritten';
14
}
15

  
16
sub translate_currency_name {
17
  my ($self, $name) = @_;
18

  
19
  return $name if (!$self->options->{translate});
20
  return $self->options->{translate}->{$name} if $self->options->{translate}->{$name};
21
  return $name;
22
}
23

  
24

  
25
1;
26

  
27

  
28
__END__
29

  
30
=encoding utf-8
31

  
32
=head1 NAME
33

  
34
SL::BackgroundJob::UpdateExchangerates::Base - Base class for background job to update exchange rates.
35

  
36
=head1 SYNOPSIS
37

  
38
  # in update-worker:
39
  use parent qw(SL::BackgroundJob::UpdateExchangerates::Base);
40

  
41
  # implement interface
42
  sub update_rates {
43
    my ($self, $rates) = @_;
44

  
45
    foreach my $rate (@$rates) {
46
      my $from = $self->translate_currency_name($rate->{from}->name);
47
      my $to   = $self->translate_currency_name($rate->{to}->name);
48
      if ( $from eq 'EUR' && $to eq 'USD') {
49
        $rate->{rate} = 0.9205 if $rate->{dir} eq 'buy';
50
        $rate->{rate} = 0.9202 if $rate->{dir} eq 'sell';
51
      }
52
    }
53
  }
54

  
55
=head1 DESCRIPTION
56

  
57
This is a base class for a worker to update exchange rates.
58

  
59
=head1 INTERFACE
60

  
61
=over 4
62

  
63
=item C<update_rates $rates>
64

  
65
Your class will be instanciated and the update_rates method will be invoked.
66
This method can update known requeseted rates. Therefor an array of hashes with
67
information of the requested rates is provided. Each hash consists of the
68
following keys:
69

  
70
=over 5
71

  
72
=item
73

  
74
from: currency (instance of SL::DB::Currency) to be converted from
75

  
76
=item
77

  
78
to: currency (instance of SL::DB::Currency) to be converted to
79

  
80
=item
81

  
82
dir: 'bye' or 'sell'
83

  
84
=back
85

  
86
Your class should add a 'rate'-entry to each hash, if it can provide the rate
87
information. If not, it should leave the hash-entry as it is.
88

  
89
=back
90

  
91
=head1 FUNCTIONS
92

  
93
=over 4
94

  
95
=item C<translate_currency_name $name>
96

  
97
Returns the translated currency name, if a translation is given. This can be used to translate client specific
98
currency notations to the one used by the worker module. Translations are give as data to the background job:
99

  
100
options:
101
  translate:
102
    £: GBP
103

  
104
=back
105

  
106
=head1 AUTHOR
107

  
108
Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt>
109

  
110
=cut
111

  

Auch abrufbar als: Unified diff