Skip to main content

ferric_fred/
order_by.rs

1/// Field to order `series/search` results by (the `order_by` request
2/// parameter). Request-only, so it carries [`query_code`](OrderBy::query_code)
3/// and is `#[non_exhaustive]` but has no `Other` variant.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum OrderBy {
7    /// Full-text search relevance (`search_rank`, FRED's default for a
8    /// full-text search).
9    SearchRank,
10    /// Series identifier (`series_id`).
11    SeriesId,
12    /// Series title (`title`).
13    Title,
14    /// Units description (`units`).
15    Units,
16    /// Native frequency (`frequency`).
17    Frequency,
18    /// Seasonal adjustment (`seasonal_adjustment`).
19    SeasonalAdjustment,
20    /// Popularity score (`popularity`).
21    Popularity,
22    /// Group popularity score (`group_popularity`).
23    GroupPopularity,
24    /// When the series was last updated (`last_updated`).
25    LastUpdated,
26    /// First observation date (`observation_start`).
27    ObservationStart,
28    /// Last observation date (`observation_end`).
29    ObservationEnd,
30}
31
32impl OrderBy {
33    /// The FRED query code for this ordering.
34    pub fn query_code(self) -> &'static str {
35        match self {
36            Self::SearchRank => "search_rank",
37            Self::SeriesId => "series_id",
38            Self::Title => "title",
39            Self::Units => "units",
40            Self::Frequency => "frequency",
41            Self::SeasonalAdjustment => "seasonal_adjustment",
42            Self::Popularity => "popularity",
43            Self::GroupPopularity => "group_popularity",
44            Self::LastUpdated => "last_updated",
45            Self::ObservationStart => "observation_start",
46            Self::ObservationEnd => "observation_end",
47        }
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn query_codes_match_fred() {
57        assert_eq!(OrderBy::SearchRank.query_code(), "search_rank");
58        assert_eq!(OrderBy::Popularity.query_code(), "popularity");
59        assert_eq!(OrderBy::LastUpdated.query_code(), "last_updated");
60    }
61}