Skip to content

Commit

Permalink
Merge pull request #135 from patrickomatic/dataValidation-operator-su…
Browse files Browse the repository at this point in the history
…pport

support for dataValidation.operator
  • Loading branch information
MathNya authored Oct 22, 2023
2 parents b454821 + ce79234 commit af61aa3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 36 deletions.
3 changes: 3 additions & 0 deletions src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ pub use self::formula::*;
mod data_validation_values;
pub use self::data_validation_values::*;

mod data_validation_operator_values;
pub use self::data_validation_operator_values::*;

mod data_validation;
pub use self::data_validation::*;

Expand Down
70 changes: 34 additions & 36 deletions src/structs/data_validation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// dataValidation
use super::BooleanValue;
use super::DataValidationOperatorValues;
use super::DataValidationValues;
use super::EnumValue;
use super::SequenceOfReferences;
Expand All @@ -15,6 +16,7 @@ use writer::driver::*;
#[derive(Default, Debug, Clone)]
pub struct DataValidation {
r#type: EnumValue<DataValidationValues>,
operator: EnumValue<DataValidationOperatorValues>,
allow_blank: BooleanValue,
show_input_message: BooleanValue,
show_error_message: BooleanValue,
Expand All @@ -34,6 +36,15 @@ impl DataValidation {
self
}

pub fn get_operator(&self) -> &DataValidationOperatorValues {
self.operator.get_value()
}

pub fn set_operator(&mut self, value: DataValidationOperatorValues) -> &mut Self {
self.operator.set_value(value);
self
}

pub fn get_allow_blank(&self) -> &bool {
self.allow_blank.get_value()
}
Expand Down Expand Up @@ -116,53 +127,36 @@ impl DataValidation {
e: &BytesStart,
empty_flg: bool,
) {
match get_attribute(e, b"type") {
Some(v) => {
self.r#type.set_value_string(v);
}
None => {}
if let Some(v) = get_attribute(e, b"type") {
self.r#type.set_value_string(v);
}

match get_attribute(e, b"allowBlank") {
Some(v) => {
self.allow_blank.set_value_string(v);
}
None => {}
if let Some(v) = get_attribute(e, b"operator") {
self.operator.set_value_string(v);
}

match get_attribute(e, b"showInputMessage") {
Some(v) => {
self.show_input_message.set_value_string(v);
}
None => {}
if let Some(v) = get_attribute(e, b"allowBlank") {
self.allow_blank.set_value_string(v);
}

match get_attribute(e, b"showErrorMessage") {
Some(v) => {
self.show_error_message.set_value_string(v);
}
None => {}
if let Some(v) = get_attribute(e, b"showInputMessage") {
self.show_input_message.set_value_string(v);
}

match get_attribute(e, b"promptTitle") {
Some(v) => {
self.prompt_title.set_value_string(v);
}
None => {}
if let Some(v) = get_attribute(e, b"showErrorMessage") {
self.show_error_message.set_value_string(v);
}

match get_attribute(e, b"prompt") {
Some(v) => {
self.prompt.set_value_string(v);
}
None => {}
if let Some(v) = get_attribute(e, b"promptTitle") {
self.prompt_title.set_value_string(v);
}

match get_attribute(e, b"sqref") {
Some(v) => {
self.sequence_of_references.set_sqref(v);
}
None => {}
if let Some(v) = get_attribute(e, b"prompt") {
self.prompt.set_value_string(v);
}

if let Some(v) = get_attribute(e, b"sqref") {
self.sequence_of_references.set_sqref(v);
}

if empty_flg {
Expand Down Expand Up @@ -217,6 +211,10 @@ impl DataValidation {
));
}

if self.operator.has_value() {
attributes.push(("operator", self.operator.get_value_string()));
}

if self.show_error_message.has_value() {
attributes.push((
"showErrorMessage",
Expand All @@ -233,7 +231,7 @@ impl DataValidation {
}

let sequence_of_references = &self.sequence_of_references.get_sqref();
if sequence_of_references != "" {
if !sequence_of_references.is_empty() {
attributes.push(("sqref", sequence_of_references));
}

Expand Down
53 changes: 53 additions & 0 deletions src/structs/data_validation_operator_values.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use super::EnumTrait;
use std::str::FromStr;

#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum DataValidationOperatorValues {
Between,
Equal,
GreaterThan,
GreaterThanOrEqual,
LessThan,
LessThanOrEqual,
NotBetween,
NotEqual,
}

impl EnumTrait for DataValidationOperatorValues {
fn get_value_string(&self) -> &str {
match self {
Self::Between => "between",
Self::Equal => "equal",
Self::GreaterThan => "greaterThan",
Self::GreaterThanOrEqual => "greaterThanOrEqual",
Self::LessThan => "lessThan",
Self::LessThanOrEqual => "lessThanOrEqual",
Self::NotBetween => "notBetween",
Self::NotEqual => "notEqual",
}
}
}

impl Default for DataValidationOperatorValues {
fn default() -> Self {
Self::LessThan
}
}

impl FromStr for DataValidationOperatorValues {
type Err = ();

fn from_str(input: &str) -> Result<Self, Self::Err> {
Ok(match input {
"between" => Self::Between,
"equal" => Self::Equal,
"greaterThan" => Self::GreaterThan,
"greaterThanOrEqual" => Self::GreaterThanOrEqual,
"lessThan" => Self::LessThan,
"lessThanOrEqual" => Self::LessThanOrEqual,
"notBetween" => Self::NotBetween,
"notEqual" => Self::NotEqual,
_ => return Err(()),
})
}
}

0 comments on commit af61aa3

Please sign in to comment.