mirror of
https://github.com/lov3b/ecb-rates.git
synced 2025-02-22 18:00:11 +01:00
rename view
This commit is contained in:
parent
5f3a075580
commit
65ad88acae
26
README.md
26
README.md
@ -16,15 +16,21 @@ Congratulations! Now the cli binary `ecb-rates` will be in your cargo bin folder
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Fetch and display select currencies:
|
#### Fetch in different views
|
||||||
- as an ASCII table
|
|
||||||
- in JSON prettified
|
- Last available day.
|
||||||
- in JSON minified
|
- Last 90 days
|
||||||
- Fetch in different "resolutions":
|
- Since the dawn of the *EUR*
|
||||||
- Last available day.
|
|
||||||
- Since the dawn of the *EUR*
|
#### Display select currencies
|
||||||
- in day resolution
|
|
||||||
- in 90 day resolution
|
- as an ASCII table
|
||||||
|
- in JSON prettified
|
||||||
|
- in JSON minified
|
||||||
|
|
||||||
|
#### Cache
|
||||||
|
|
||||||
|
It features an extensive cache, which will [calculate hollidays](src/holiday.rs) in order to know whether to invalidate it or not.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
@ -43,4 +49,4 @@ NOK 11.7385
|
|||||||
|
|
||||||
## Acknowledgment
|
## Acknowledgment
|
||||||
|
|
||||||
The data is (obviously) provided by the [European Central Bank](https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html)
|
The data is (obviously) provided by the [European Central Bank](https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html)
|
18
src/cache/cache.rs
vendored
18
src/cache/cache.rs
vendored
@ -5,7 +5,7 @@ use std::path::Path;
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::cli::Resolution;
|
use crate::cli::View;
|
||||||
use crate::os::Os;
|
use crate::os::Os;
|
||||||
|
|
||||||
use super::CacheLine;
|
use super::CacheLine;
|
||||||
@ -51,20 +51,20 @@ impl Cache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cache_line(&self, resolution: Resolution) -> Option<&CacheLine> {
|
pub fn get_cache_line(&self, resolution: View) -> Option<&CacheLine> {
|
||||||
match resolution {
|
match resolution {
|
||||||
Resolution::TODAY => self.day.as_ref(),
|
View::TODAY => self.day.as_ref(),
|
||||||
Resolution::HistDays90 => self.hist_90.as_ref(),
|
View::HistDays90 => self.hist_90.as_ref(),
|
||||||
Resolution::HistDaysAll => self.hist_day.as_ref(),
|
View::HistDaysAll => self.hist_day.as_ref(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_cache_line(&mut self, resolution: Resolution, cache_line: CacheLine) {
|
pub fn set_cache_line(&mut self, resolution: View, cache_line: CacheLine) {
|
||||||
let cache_line_opt = Some(cache_line);
|
let cache_line_opt = Some(cache_line);
|
||||||
match resolution {
|
match resolution {
|
||||||
Resolution::TODAY => self.day = cache_line_opt,
|
View::TODAY => self.day = cache_line_opt,
|
||||||
Resolution::HistDays90 => self.hist_90 = cache_line_opt,
|
View::HistDays90 => self.hist_90 = cache_line_opt,
|
||||||
Resolution::HistDaysAll => self.hist_day = cache_line_opt,
|
View::HistDaysAll => self.hist_day = cache_line_opt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
src/cli.rs
19
src/cli.rs
@ -46,8 +46,8 @@ pub struct Cli {
|
|||||||
pub max_decimals: u8,
|
pub max_decimals: u8,
|
||||||
|
|
||||||
/// Amount of data
|
/// Amount of data
|
||||||
#[arg(value_enum, default_value_t = Resolution::TODAY, long="resolution", short='r')]
|
#[arg(value_enum, default_value_t = View::TODAY, long="resolution", short='r')]
|
||||||
pub resolution: Resolution,
|
pub resolution: View,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, ValueEnum)]
|
#[derive(Debug, Clone, Copy, ValueEnum)]
|
||||||
@ -57,20 +57,21 @@ pub enum SortBy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, ValueEnum)]
|
#[derive(Debug, Clone, Copy, ValueEnum)]
|
||||||
pub enum Resolution {
|
pub enum View {
|
||||||
|
#[clap(name = "last-day")]
|
||||||
TODAY,
|
TODAY,
|
||||||
#[clap(name = "hist-90-days")]
|
#[clap(name = "last-90-days")]
|
||||||
HistDays90,
|
HistDays90,
|
||||||
#[clap(name = "hist-all-days")]
|
#[clap(name = "all-days")]
|
||||||
HistDaysAll,
|
HistDaysAll,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resolution {
|
impl View {
|
||||||
pub fn to_ecb_url(&self) -> &'static str {
|
pub fn to_ecb_url(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Resolution::TODAY => ecb_url::TODAY,
|
View::TODAY => ecb_url::TODAY,
|
||||||
Resolution::HistDays90 => ecb_url::hist::DAYS_90,
|
View::HistDays90 => ecb_url::hist::DAYS_90,
|
||||||
Resolution::HistDaysAll => ecb_url::hist::DAYS_ALL,
|
View::HistDaysAll => ecb_url::hist::DAYS_ALL,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user