| 1 | use super::{ByColumnName, ByCondition, ByContent}; |
| 2 | |
| 3 | /// An abstract factory for locations, to be used to find different things on the table. |
| 4 | #[derive (Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, Hash)] |
| 5 | pub struct Locator; |
| 6 | |
| 7 | impl Locator { |
| 8 | /// Constructs a new location searcher for a cells with a given content. |
| 9 | pub fn content<S>(text: S) -> ByContent<S> |
| 10 | where |
| 11 | S: AsRef<str>, |
| 12 | { |
| 13 | ByContent::new(text) |
| 14 | } |
| 15 | |
| 16 | /// Constructs a new location searcher for a column by its header. |
| 17 | pub fn column<S>(text: S) -> ByColumnName<S> |
| 18 | where |
| 19 | S: AsRef<str>, |
| 20 | { |
| 21 | ByColumnName::new(text) |
| 22 | } |
| 23 | |
| 24 | /// Constructs a new location searcher with a specified condition closure. |
| 25 | /// |
| 26 | /// Return `true` if it shall be included in output. |
| 27 | /// Otherwise return `false`. |
| 28 | pub fn by<F>(condition: F) -> ByCondition<F> |
| 29 | where |
| 30 | F: Fn(&str) -> bool, |
| 31 | { |
| 32 | ByCondition::new(condition) |
| 33 | } |
| 34 | } |
| 35 | |