}
pub struct SeriesItemsIter<'a> {
data: &'a SeriesItems,
count: usize,
}
impl<'a> Iterator for SeriesItemsIter<'a> {
type Item = &'a SeriesItem;
fn next(&mut self) -> Option<Self::Item> {
if self.count == self.data.0.len() {
None
} else {
self.count += 1;
Some(&self.data.0[self.count - 1])
}
}
}
#[derive(Debug, Deserialize)]
pub struct SeriesItems(Vec<SeriesItem>);
impl SeriesItems {
pub fn iter<'a>(&'a self) -> SeriesItemsIter {
SeriesItemsIter {
data: &self,
count: 0,
}
}
/// Include only series with series equal to title.
pub fn equals_one_of(&self, titles: Vec<&str>) -> SeriesItems {
let mut v = Vec::new();
for series in self.iter() {
if titles.iter().any(|title| *title == series.title) {
v.push(series.clone());
}
}
SeriesItems(v)
}
/// Exclude if includes phrase.
pub fn exclude_phrases(&self, phrases: Vec<&str>) -> SeriesItems {
let mut v = Vec::new();
for series in self.iter() {
if !phrases.iter().any(|title| series.title.contains(title)) {
v.push(series.clone());
}
}
SeriesItems(v)
}
/// Only include if includes phrase.
pub fn only_include(&self, phrases: Vec<&str>) -> SeriesItems {
let mut v = Vec::new();
for series in &self.0 {
if phrases.iter().any(|title| series.title.contains(title)) {
v.push(series.clone());
}
}
SeriesItems(v)
}
pub fn inner(&self) -> Vec<SeriesItem> {
(*self.0).to_vec()
}