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
pub(crate) trait MakingUrlFormat {
/// is overridden in actual usage with applicable data structures.
fn generate_url_format(&self) -> String {
"nothing".to_string()
}
/// generates suitable currency format to be used in the latest version of the url.
fn generate_currency_format(currency: &str, exchange_type: &str, ytl_mode: bool) -> String {
if ytl_mode {
return format!("series=TP.DK.{}.{}.YTL", currency, exchange_type);
}
format!("series=TP.DK.{}.{}", currency, exchange_type)
}
/// generates suitable multiple currency series url format to be used in the latest version of the url.
fn generate_multiple_currency_format(currencies: Vec<&str>, exchange_type: &str, ytl_mode: bool) -> String {
let mut buffer = String::from("series=");
for currency in currencies {
if ytl_mode {
buffer.push_str(&format!("TP.DK.{}.{}.YTL-", currency, exchange_type));
continue;
}
buffer.push_str(&format!("TP.DK.{}.{}-", currency, exchange_type));
}
buffer.pop();
buffer
}
/// generates url format of a given buying/selling type currency to be combined with its corresponding
/// selling/buying version later.
///
/// Ytl mode given as parameter configures return value format of currency series.
///
/// Printout examples:
/// ``` Example
/// 1. Ytl Mode On : TP.DK.USA.A.YTL
/// 2. Ytl Mode Off: TP.DK.USA.A
///
/// ```
/// Later couples:
/// ``` Example
/// 1. -> TP.DK.USA.S.YTL
/// 2. -> TP.DK.USA.S
///
/// ("->" means "will be combined with")
/// ```
fn generate_currency_format_for_combination(currency: &str, exchange_type: &str, ytl_mode: bool) -> String {
if ytl_mode {
return format!("TP.DK.{}.{}.YTL", currency, exchange_type);
}
format!("TP.DK.{}.{}", currency, exchange_type)
}
/// generates url format of given buying/selling type currencies to be combined with their corresponding
/// selling/buying versions later.
///
/// Ytl mode given as parameter configures return value format of currency series.
///
/// Printout examples:
/// ```
/// 1. Ytl Mode On : TP.DK.USD.A.YTL-TP.DK.EUR.A.YTL-TP.DK.GBP.A.YTL
/// 2. Ytl Mode Off: TP.DK.USD.S-TP.DK.AUD.S-TP.DK.GBP.S
///
/// ```
/// Later couples:
/// ``` Example
/// 1. -> TP.DK.USA.S.YTL
/// 2. -> TP.DK.USA.S
///
/// ("->" means "will be combined with")
/// ```
fn generate_multiple_currency_format_for_combination(
currencies: Vec<&str>,
exchange_type: &str,
ytl_mode: bool
) -> String {
let mut buffer = String::new();
for currency in currencies {
if ytl_mode {
buffer.push_str(&format!("TP.DK.{}.{}.YTL-", currency, exchange_type));
continue;
}
buffer.push_str(&format!("TP.DK.{}.{}-", currency, exchange_type));
}
buffer.pop();
buffer
}
/// generates url format combination of given two currency series.
///
/// This function should be used when double exchange type is provided.
///
/// Buying and Selling Types Output Examples:
/// ``` Example
/// Buying: TP.DK.A.JPY, Selling: TP.DK.S.JPY
///
/// Combined_series: TP.DK.A.JPY-TP.DK.S.JPY
/// ```
fn generate_two_combined_currencies_format(former_currency: &str, latter_currency: &str) -> String {
format!("series={}-{}", former_currency, latter_currency)
}
}