quanttide_work/criterion/
items.rs1use super::model::{Criterion, RuleKind};
8
9#[derive(Debug, Clone)]
11pub struct RuleItem {
12 pub description: String,
13 pub kind: Option<RuleKind>,
14 pub args: Vec<String>,
15}
16
17impl RuleItem {
18 pub fn machine(&self) -> bool {
19 self.kind.is_some()
20 }
21}
22
23pub fn items_of(criteria: &[Criterion]) -> Vec<RuleItem> {
25 criteria
26 .iter()
27 .map(|criterion| {
28 let description = criterion.text();
29 let (kind, args) = match criterion {
30 Criterion::PathExists { path, .. } => {
31 (Some(RuleKind::PathExists), vec![path.clone()])
32 }
33 Criterion::PathAbsent { absent, .. } => {
34 (Some(RuleKind::PathAbsent), vec![absent.clone()])
35 }
36 Criterion::FileContains { file, contains, .. } => (
37 Some(RuleKind::FileContains),
38 vec![file.clone(), contains.clone()],
39 ),
40 Criterion::CommandRun { run, .. } => {
41 (Some(RuleKind::CommandRun), vec![run.clone()])
42 }
43 Criterion::AgentJudgement { .. } | Criterion::HumanGate { .. } => {
44 (None, Vec::new())
45 }
46 };
47 RuleItem {
48 description,
49 kind,
50 args,
51 }
52 })
53 .collect()
54}