From 94d73b2a366441ee82e729f8df4d02cc5e2ce08f Mon Sep 17 00:00:00 2001 From: kageru Date: Mon, 30 Jan 2023 11:51:36 +0100 Subject: [PATCH] Add filter by link rating --- src/filter.rs | 1 + src/parser.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/filter.rs b/src/filter.rs index f274884..618b8d7 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -61,6 +61,7 @@ pub fn build_filter(query: RawCardFilter) -> Result { Box::new(move |card| card.def.is_none() && card.link_rating.is_none() && card.card_type.contains("monster")) } RawCardFilter(Field::Level, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(card.level, n)), + RawCardFilter(Field::LinkRating, op, Value::Numerical(n)) => Box::new(move |card| op.filter_number(card.link_rating, n)), RawCardFilter(Field::Type, Operator::Equal, Value::String(s)) => Box::new(move |card| card.r#type == s), RawCardFilter(Field::Type, Operator::NotEqual, Value::String(s)) => Box::new(move |card| card.r#type != s), RawCardFilter(Field::Attribute, Operator::Equal, Value::String(s)) => Box::new(move |card| card.attribute.contains(&s)), diff --git a/src/parser.rs b/src/parser.rs index 2558b0c..aca4cc6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -65,11 +65,12 @@ pub enum Field { Atk = 1, Def = 2, Level = 3, - Type = 4, - Attribute = 5, - Class = 6, - Name = 7, - Text = 8, + LinkRating = 4, + Type = 5, + Attribute = 6, + Class = 7, + Name = 8, + Text = 9, } impl Display for Field { @@ -83,6 +84,7 @@ impl Display for Field { Self::Level => "level/rank", Self::Atk => "ATK", Self::Def => "DEF", + Self::LinkRating => "link rating", }) } } @@ -98,6 +100,7 @@ impl FromStr for Field { "attribute" | "attr" | "a" => Self::Attribute, "c" | "class" => Self::Class, "o" | "eff" | "text" | "effect" | "e" => Self::Text, + "lr" | "linkrating" => Self::LinkRating, _ => Err(s.to_string())?, }) }