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
24
README.md
24
README.md
@ -16,15 +16,21 @@ Congratulations! Now the cli binary `ecb-rates` will be in your cargo bin folder
|
||||
|
||||
## Features
|
||||
|
||||
- Fetch and display select currencies:
|
||||
- as an ASCII table
|
||||
- in JSON prettified
|
||||
- in JSON minified
|
||||
- Fetch in different "resolutions":
|
||||
- Last available day.
|
||||
- Since the dawn of the *EUR*
|
||||
- in day resolution
|
||||
- in 90 day resolution
|
||||
#### Fetch in different views
|
||||
|
||||
- Last available day.
|
||||
- Last 90 days
|
||||
- Since the dawn of the *EUR*
|
||||
|
||||
#### Display select currencies
|
||||
|
||||
- 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
|
||||
|
||||
|
18
src/cache/cache.rs
vendored
18
src/cache/cache.rs
vendored
@ -5,7 +5,7 @@ use std::path::Path;
|
||||
use anyhow::Context;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::cli::Resolution;
|
||||
use crate::cli::View;
|
||||
use crate::os::Os;
|
||||
|
||||
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 {
|
||||
Resolution::TODAY => self.day.as_ref(),
|
||||
Resolution::HistDays90 => self.hist_90.as_ref(),
|
||||
Resolution::HistDaysAll => self.hist_day.as_ref(),
|
||||
View::TODAY => self.day.as_ref(),
|
||||
View::HistDays90 => self.hist_90.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);
|
||||
match resolution {
|
||||
Resolution::TODAY => self.day = cache_line_opt,
|
||||
Resolution::HistDays90 => self.hist_90 = cache_line_opt,
|
||||
Resolution::HistDaysAll => self.hist_day = cache_line_opt,
|
||||
View::TODAY => self.day = cache_line_opt,
|
||||
View::HistDays90 => self.hist_90 = 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,
|
||||
|
||||
/// Amount of data
|
||||
#[arg(value_enum, default_value_t = Resolution::TODAY, long="resolution", short='r')]
|
||||
pub resolution: Resolution,
|
||||
#[arg(value_enum, default_value_t = View::TODAY, long="resolution", short='r')]
|
||||
pub resolution: View,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, ValueEnum)]
|
||||
@ -57,20 +57,21 @@ pub enum SortBy {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, ValueEnum)]
|
||||
pub enum Resolution {
|
||||
pub enum View {
|
||||
#[clap(name = "last-day")]
|
||||
TODAY,
|
||||
#[clap(name = "hist-90-days")]
|
||||
#[clap(name = "last-90-days")]
|
||||
HistDays90,
|
||||
#[clap(name = "hist-all-days")]
|
||||
#[clap(name = "all-days")]
|
||||
HistDaysAll,
|
||||
}
|
||||
|
||||
impl Resolution {
|
||||
impl View {
|
||||
pub fn to_ecb_url(&self) -> &'static str {
|
||||
match self {
|
||||
Resolution::TODAY => ecb_url::TODAY,
|
||||
Resolution::HistDays90 => ecb_url::hist::DAYS_90,
|
||||
Resolution::HistDaysAll => ecb_url::hist::DAYS_ALL,
|
||||
View::TODAY => ecb_url::TODAY,
|
||||
View::HistDays90 => ecb_url::hist::DAYS_90,
|
||||
View::HistDaysAll => ecb_url::hist::DAYS_ALL,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user