diff options
Diffstat (limited to 'src/barbfile.rs')
-rw-r--r-- | src/barbfile.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/barbfile.rs b/src/barbfile.rs index 35b0224..91ffd0a 100644 --- a/src/barbfile.rs +++ b/src/barbfile.rs @@ -2,6 +2,7 @@ use regex::Regex; use std::str::FromStr; use std::string::ToString; use std::{error::Error, fmt}; +use jq_rs; #[derive(Debug)] pub struct BarbParseError {} @@ -126,6 +127,12 @@ impl BarbFilter { pub fn filter(&self) -> &String { &self.filter } + + pub fn apply(&self, body: &String) -> Result<String, String> { + jq_rs::run(self.filter.as_str(), body.as_str()) + .map_err(|x| x.to_string()) + .map(|x| String::from(x.trim().trim_matches('"'))) + } } struct BarbPreamble { |