refactor(parse_field): rewrite fields parser util

Field parser has been rewritten as the signal reduce page uses a Entry
inputs instead TextView.
This commit is contained in:
doryan 2024-08-15 23:23:12 +04:00
parent e9764cf0e8
commit 11ba24d7ed
2 changed files with 19 additions and 28 deletions

View File

@ -1,28 +0,0 @@
pub fn parse_fields(all_inputs: Vec<Input>) -> Result<SignalReduce> {
let mut values: [f64; 6] = [0.0; 6];
for (i, input) in all_inputs.iter().enumerate() {
let input_text_buffer: TextBuffer = input.clone().get_input().buffer();
let extracted_value = f64::from_str(
input_text_buffer
.text(
&input_text_buffer.start_iter(),
&input_text_buffer.end_iter(),
false,
)
.as_str()
.trim(),
)?;
values[i] = extracted_value;
}
Ok(SignalReduce {
length: values[0],
wire_resistance: values[1],
wire_capacity: values[2],
source_resistance: values[3],
source_voltage: values[4],
frequency: values[5],
})
}

View File

@ -21,3 +21,22 @@ pub fn get_error_message(error: Error) -> Option<&'static str> {
}
}
pub fn parse_fields(all_inputs: Vec<Input<Entry>>) -> Result<SignalReduce> {
let mut values: [f64; 6] = [0.0; 6];
for (i, input) in all_inputs.iter().enumerate() {
let input_text_buffer = input.get_input();
let extracted_value = f64::from_str(input_text_buffer.text().as_str().trim())?;
values[i] = extracted_value;
}
Ok(SignalReduce {
length: values[0],
wire_resistance: values[1],
wire_capacity: values[2],
source_resistance: values[3],
source_voltage: values[4],
frequency: values[5],
})
}