diff --git a/README.md b/README.md index c9adb3d..4d02452 100644 --- a/README.md +++ b/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 @@ -43,4 +49,4 @@ NOK 11.7385 ## 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) \ No newline at end of file diff --git a/src/cache/cache.rs b/src/cache/cache.rs index 7d8fd3f..c6ff4e3 100644 --- a/src/cache/cache.rs +++ b/src/cache/cache.rs @@ -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, } } diff --git a/src/cli.rs b/src/cli.rs index ef92577..f531f9d 100644 --- a/src/cli.rs +++ b/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, } } }