uls_core/records/
control_point.rs1use super::common::*;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct ControlPointRecord {
7 pub unique_system_identifier: i64,
8 pub uls_file_number: Option<String>,
9 pub ebf_number: Option<String>,
10 pub call_sign: Option<String>,
11 pub control_point_action_performed: Option<char>,
12 pub control_point_number: Option<i32>,
13 pub control_address: Option<String>,
14 pub control_city: Option<String>,
15 pub state_code: Option<String>,
16 pub control_phone: Option<String>,
17 pub control_county: Option<String>,
18}
19
20impl ControlPointRecord {
21 pub fn from_fields(fields: &[&str]) -> Self {
22 Self {
23 unique_system_identifier: parse_i64_or_default(fields.get(1).unwrap_or(&"")),
24 uls_file_number: parse_opt_string(fields.get(2).unwrap_or(&"")),
25 ebf_number: parse_opt_string(fields.get(3).unwrap_or(&"")),
26 call_sign: parse_opt_string(fields.get(4).unwrap_or(&"")),
27 control_point_action_performed: parse_opt_char(fields.get(5).unwrap_or(&"")),
28 control_point_number: parse_opt_i32(fields.get(6).unwrap_or(&"")),
29 control_address: parse_opt_string(fields.get(7).unwrap_or(&"")),
30 control_city: parse_opt_string(fields.get(8).unwrap_or(&"")),
31 state_code: parse_opt_string(fields.get(9).unwrap_or(&"")),
32 control_phone: parse_opt_string(fields.get(10).unwrap_or(&"")),
33 control_county: parse_opt_string(fields.get(11).unwrap_or(&"")),
34 }
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn test_control_point_from_fields() {
44 let fields = vec![
45 "CP",
46 "12345",
47 "ULS123",
48 "EBF456",
49 "W1TEST",
50 "A",
51 "1",
52 "123 Main St",
53 "Springfield",
54 "IL",
55 "555-555-1234",
56 "Sangamon",
57 ];
58 let cp = ControlPointRecord::from_fields(&fields);
59
60 assert_eq!(cp.unique_system_identifier, 12345);
61 assert_eq!(cp.call_sign, Some("W1TEST".to_string()));
62 assert_eq!(cp.control_city, Some("Springfield".to_string()));
63 assert_eq!(cp.state_code, Some("IL".to_string()));
64 }
65}