Skip to content

Commit

Permalink
#50 working on printing policy as text
Browse files Browse the repository at this point in the history
  • Loading branch information
dsietz committed Aug 29, 2023
1 parent 8d61bc0 commit 5748ca1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
72 changes: 71 additions & 1 deletion src/dua/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ impl DUP {
/// );
/// }
/// ```
///
pub fn new(nme: String, descr: String, ver: String) -> Self {
DUP {
name: nme,
Expand Down Expand Up @@ -274,11 +273,82 @@ impl DUP {
self.uses.insert(usage.get_key().clone(), usage);
}

/// Converts the policy to a human readable format as text
///
/// #Example
///
/// ```rust
/// extern crate pbd;
///
/// use pbd::dua::policy::DUP;
/// use pbd::dua::data_category::DataCategoryFactory;
/// use pbd::dua::data_subject::DataSubjectFactory;
/// use pbd::dua::data_use::DataUseFactory;
///
/// fn main() {
/// let cfactory = DataCategoryFactory::new();
/// let sfactory = DataSubjectFactory::new();
/// let ufactory = DataUseFactory::new();
/// let mut dup = DUP::new(
/// "General Marketing Policy".to_string(),
/// "This policy explains the manner in which your data will be used for marketing purposes.".to_string(),
/// "1.0.0".to_string()
/// );
///
/// dup.associate_category(
/// cfactory
/// .get_category_by_key("user.behavior.browsing_history".to_string())
/// .unwrap(),
/// );
/// dup.associate_category(
/// cfactory
/// .get_category_by_key("user.behavior.media_consumption".to_string())
/// .unwrap(),
/// );
/// dup.associate_subject(sfactory.get_subject_by_key("customer".to_string()).unwrap());
/// dup.associate_subject(sfactory.get_subject_by_key("prospect".to_string()).unwrap());
/// dup.associate_use(
/// ufactory
/// .get_use_by_key("marketing.advertising.profiling".to_string())
/// .unwrap(),
/// );
/// dup.associate_use(
/// ufactory
/// .get_use_by_key("marketing.advertising.serving".to_string())
/// .unwrap(),
/// );
/// dup.associate_use(
/// ufactory
/// .get_use_by_key("marketing.communications.email".to_string())
/// .unwrap(),
/// );
///
/// print!("{}", dup.as_text());
///
/// /* General Marketing Policy
/// * (version: 1.0.0)
/// *
/// * This policy explains the manner in which your data will be used for marketing purposes.
/// *
/// * Data will be collected from the following types of users: Customer and Prospect.
/// * The data being collected will be limited to the following data: Browsing History and Media Consumption.
/// * The data collected can be used for the following purposes: Profiling for Advertising, Essential for Serving Ads and Marketing Email Communications.
/// */
/// }
/// ```
pub fn as_text(&mut self) -> String {
let line_feed = "\r\n";
let mut policy = String::new();
policy.push_str(&self.name);
policy.push_str(line_feed);
policy.push_str("(version: ");
policy.push_str(&self.version);
policy.push_str(")");
policy.push_str(line_feed);
policy.push_str(line_feed);

policy.push_str(&self.description);
policy.push_str(line_feed);
policy.push_str(line_feed);

// Data Subjects
Expand Down
3 changes: 3 additions & 0 deletions tests/output/policy.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
General Policy
(version: 1.0.1)

This is a high-level policy.

Data will be collected from the following types of users: Customer and Prospect.
The data being collected will be limited to the following data: Browsing History and Media Consumption.
Expand Down

0 comments on commit 5748ca1

Please sign in to comment.