-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
121 lines (86 loc) · 3.24 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
NAME
Finance::Currency::Convert::SCSB - Query currency exchange rates from
SCSB (Shanghai Commercial and Savings Bank)
VERSION
v0.1.0
DESCRIPTION
This module crawl and parses currency exchange rates listed on this
web:
https://ibank.scsb.com.tw/netbank.portal?_nfpb=true&_pageLabel=page_other12&_nfls=false
. All prices on this page are in TWD (Taiwan Dollar.) For this reason,
it can only convert some non-TWD currency to TWD.
FUNCTIONS
The following functions are exportable, but not exported by default.
Some annotations with fictional Types are used in the following
documentation just for the purpose of explaination. No Type-validation
are implemented, nor are they defined. Not in this module.
"Num" referrer to a number, "Currency" is a short string such as 'TWD',
'USD'. The notation `Maybe[T]` means that the variable can contain a
value either be of type T, or undef. See: Types::Standard or
Moose::Util::TypeConstraints for more description of these notations.
convert_currency
Definition:
($error :Maybe[Str], $result :Maybe[Num]) =
convert_currency(
$amount :Num
$from :Currency,
$to :Currency
)
When it is successful, $error is undef and $result contained the parsed
output.
When error of some kind happens, $error contains the error message and
$result is undef.
Example Usage:
# Error-checking
my ($err, $n) = convert_currency(100, 'USD', 'TWD');
die "Error: $err": if $err;
say "100 USD is about $n TWD";
# Ignore error message. Checks the result directly.
my $n = convert_currency(100, 'USD', 'TWD');
if ( defined($n) ) {
say "100 USD is about $n TWD";
} else {
say "Failed to convert 100 USD to TWD";
}
get_currencies
With this function, the entire exchange rate table are parsed and
returned in the special strucutre.
Definition:
($error :Maybe[Str], $result :Maybe[ArrayRef[Rate]]) =
convert_currency(
$amount :Num,
$from :Currency,
$to :Currency
)
When it is successful, $error is undef and $result contained the parsed
output.
When error of some kind happens, $error contains the error message and
$result is undef.
Usage:
# Error-checking
my ($err, $o) = get_currencies();
die "Error: $err": if $err;
do_something($o);
# Ignore error message. Checks the result directly.
my $o = get_currencies();
if ($o) {
...
} else {
...
}
The "Rate" type is a HashRef with 5 specific key-value pairs that looks
like this:
{
currency => "USD",
zh_currency_name => "美金現金",
en_currency_name => "USD CASH",
buy_at => 33.06,
sell_at => 33.56
}
This structure is just a directly translation of the rate exchange
table shown on the source web page.
AUTHOR
Kang-min Liu <[email protected]>
LICENSE
This is free software, licensed under:
The MIT (X11) License