Add header helpers for BM

This commit is contained in:
Matthias Beyer 2015-12-28 11:41:01 +01:00
parent e346f56a8e
commit 2e7621d2bd
3 changed files with 35 additions and 1 deletions

32
src/module/bm/header.rs Normal file
View file

@ -0,0 +1,32 @@
use module::helpers::header as headerhelpers;
use storage::file::header::data::FileHeaderData as FHD;
use storage::file::header::spec::FileHeaderSpec as FHS;
pub fn get_spec() -> FHS {
FHS::Map {
keys: vec![
headerhelpers::tags::spec::url_key(),
headerhelpers::tags::spec::tags_key(),
]
}
}
pub fn build_header(url: String, tags: Vec<String>) -> FHD {
FHD::Map {
keys: vec![
FHD::Key {
name: String::from("URL"),
value: Box::new(FHD::Text(url.clone()))
},
FHD::Key {
name: String::from("TAGS"),
value: Box::new(headerhelpers::tags::data::build_tag_array(tags))
}
]
}
}
pub fn get_tags_from_header(header: &FHD) -> Vec<String> {
headerhelpers::tags::data::get_tags_from_header(header)
}

View file

@ -10,6 +10,8 @@ use storage::parser::FileHeaderParser;
use storage::parser::Parser; use storage::parser::Parser;
use storage::json::parser::JsonHeaderParser; use storage::json::parser::JsonHeaderParser;
mod header;
pub struct BM<'a> { pub struct BM<'a> {
rt: &'a Runtime<'a>, rt: &'a Runtime<'a>,
} }

View file

@ -20,7 +20,7 @@ pub mod data {
use std::ops::Deref; use std::ops::Deref;
use storage::file::header::data::FileHeaderData as FHD; use storage::file::header::data::FileHeaderData as FHD;
pub fn build_tag_array(tags: &Vec<String>) -> FHD { pub fn build_tag_array(tags: Vec<String>) -> FHD {
let texttags = tags.into_iter().map(|t| FHD::Text(t.clone())).collect(); let texttags = tags.into_iter().map(|t| FHD::Text(t.clone())).collect();
FHD::Array { values: Box::new(texttags) } FHD::Array { values: Box::new(texttags) }
} }