mirror of
				https://github.com/lov3b/ecb-rates.git
				synced 2025-10-29 20:30:24 +01:00 
			
		
		
		
	rename view
This commit is contained in:
		
							
								
								
									
										18
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								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 | ||||||
|  |  | ||||||
|  | - Last available day. | ||||||
|  | - Last 90 days | ||||||
|  | - Since the dawn of the *EUR* | ||||||
|  |  | ||||||
|  | #### Display select currencies | ||||||
|  |  | ||||||
| - as an ASCII table | - as an ASCII table | ||||||
| - in JSON prettified | - in JSON prettified | ||||||
| - in JSON minified | - in JSON minified | ||||||
| - Fetch in different "resolutions": |  | ||||||
|   - Last available day. | #### Cache | ||||||
|   - Since the dawn of the *EUR* |  | ||||||
|     - in day resolution | It features an extensive cache, which will [calculate hollidays](src/holiday.rs) in order to know whether to invalidate it or not. | ||||||
|     - in 90 day resolution |  | ||||||
|  |  | ||||||
| ### Example | ### 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 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, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user