Skip to main content

cimstructs/
StreetDetail.rs

1/// Street details, in the context of address.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct StreetDetail {
4    pub id: String,
5    /// First line of a free form address or some additional address information (for example a mail stop).
6    pub address_general: String,
7    /// (if applicable) Second line of a free form address.
8    pub address_general2: String,
9    /// (if applicable) Third line of a free form address.
10    pub address_general3: String,
11    /// (if applicable) In certain cases the physical location of the place of interest does not have a direct point of entry from the street, but may be located inside a larger structure such as a building, complex, office block, apartment, etc.
12    pub building_name: String,
13    /// (if applicable) Utilities often make use of external reference systems, such as those of the town-planner's department or surveyor general's mapping system, that allocate global reference codes to streets.
14    pub code: String,
15    /// The identification by name or number, expressed as text, of the floor in the building as part of this address.
16    pub floor_identification: String,
17    /// Name of the street.
18    pub name: String,
19    /// Designator of the specific location on the street.
20    pub number: String,
21    /// Prefix to the street name. For example: North, South, East, West.
22    pub prefix: String,
23    /// Suffix to the street name. For example: North, South, East, West.
24    pub suffix: String,
25    /// Number of the apartment or suite.
26    pub suite_number: String,
27    /// Type of street. Examples include: street, circle, boulevard, avenue, road, drive, etc.
28    pub type_: String,
29    /// True if this street is within the legal geographical boundaries of the specified town (default).
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub within_town_limits: Option<bool>,
32}
33impl crate::base::CimElement for StreetDetail {
34    fn mrid(&self) -> &str { &self.id }
35    fn type_name(&self) -> &'static str { "StreetDetail" }
36    fn as_any(&self) -> &dyn std::any::Any { self }
37    fn to_json_value(&self) -> serde_json::Value {
38        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
39    }
40    fn to_block(&self) -> crate::base::RdfBlock {
41        let mut block = crate::base::RdfBlock {
42            type_name: "StreetDetail".to_string(),
43            mrid: self.id.clone(),
44            fields: std::collections::HashMap::new(),
45            duplicate_fields: std::collections::HashSet::new(),
46        };
47        if !self.address_general.is_empty() {
48            block.fields.insert("StreetDetail.addressGeneral".into(), crate::base::FieldValue::Text(self.address_general.clone()));
49        }
50        if !self.address_general2.is_empty() {
51            block.fields.insert("StreetDetail.addressGeneral2".into(), crate::base::FieldValue::Text(self.address_general2.clone()));
52        }
53        if !self.address_general3.is_empty() {
54            block.fields.insert("StreetDetail.addressGeneral3".into(), crate::base::FieldValue::Text(self.address_general3.clone()));
55        }
56        if !self.building_name.is_empty() {
57            block.fields.insert("StreetDetail.buildingName".into(), crate::base::FieldValue::Text(self.building_name.clone()));
58        }
59        if !self.code.is_empty() {
60            block.fields.insert("StreetDetail.code".into(), crate::base::FieldValue::Text(self.code.clone()));
61        }
62        if !self.floor_identification.is_empty() {
63            block.fields.insert("StreetDetail.floorIdentification".into(), crate::base::FieldValue::Text(self.floor_identification.clone()));
64        }
65        if !self.name.is_empty() {
66            block.fields.insert("StreetDetail.name".into(), crate::base::FieldValue::Text(self.name.clone()));
67        }
68        if !self.number.is_empty() {
69            block.fields.insert("StreetDetail.number".into(), crate::base::FieldValue::Text(self.number.clone()));
70        }
71        if !self.prefix.is_empty() {
72            block.fields.insert("StreetDetail.prefix".into(), crate::base::FieldValue::Text(self.prefix.clone()));
73        }
74        if !self.suffix.is_empty() {
75            block.fields.insert("StreetDetail.suffix".into(), crate::base::FieldValue::Text(self.suffix.clone()));
76        }
77        if !self.suite_number.is_empty() {
78            block.fields.insert("StreetDetail.suiteNumber".into(), crate::base::FieldValue::Text(self.suite_number.clone()));
79        }
80        if !self.type_.is_empty() {
81            block.fields.insert("StreetDetail.type".into(), crate::base::FieldValue::Text(self.type_.clone()));
82        }
83        if let Some(v) = self.within_town_limits {
84            block.fields.insert("StreetDetail.withinTownLimits".into(), crate::base::FieldValue::Text(v.to_string()));
85        }
86        block
87    }
88}
89
90impl StreetDetail {
91    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
92        let mut obj = Self::default();
93        obj.id.clone_from(&b.mrid);
94        for (key, val) in &b.fields {
95            match key.as_str() {
96                "StreetDetail.addressGeneral" => {
97                    match val {
98                        crate::base::FieldValue::Text(sv) => { obj.address_general = sv.clone(); }
99                        crate::base::FieldValue::TextList(svs) => {
100                            if let Some(sv) = svs.last() { obj.address_general = sv.clone(); }
101                        }
102                        _ => {}
103                    }
104                }
105                "StreetDetail.addressGeneral2" => {
106                    match val {
107                        crate::base::FieldValue::Text(sv) => { obj.address_general2 = sv.clone(); }
108                        crate::base::FieldValue::TextList(svs) => {
109                            if let Some(sv) = svs.last() { obj.address_general2 = sv.clone(); }
110                        }
111                        _ => {}
112                    }
113                }
114                "StreetDetail.addressGeneral3" => {
115                    match val {
116                        crate::base::FieldValue::Text(sv) => { obj.address_general3 = sv.clone(); }
117                        crate::base::FieldValue::TextList(svs) => {
118                            if let Some(sv) = svs.last() { obj.address_general3 = sv.clone(); }
119                        }
120                        _ => {}
121                    }
122                }
123                "StreetDetail.buildingName" => {
124                    match val {
125                        crate::base::FieldValue::Text(sv) => { obj.building_name = sv.clone(); }
126                        crate::base::FieldValue::TextList(svs) => {
127                            if let Some(sv) = svs.last() { obj.building_name = sv.clone(); }
128                        }
129                        _ => {}
130                    }
131                }
132                "StreetDetail.code" => {
133                    match val {
134                        crate::base::FieldValue::Text(sv) => { obj.code = sv.clone(); }
135                        crate::base::FieldValue::TextList(svs) => {
136                            if let Some(sv) = svs.last() { obj.code = sv.clone(); }
137                        }
138                        _ => {}
139                    }
140                }
141                "StreetDetail.floorIdentification" => {
142                    match val {
143                        crate::base::FieldValue::Text(sv) => { obj.floor_identification = sv.clone(); }
144                        crate::base::FieldValue::TextList(svs) => {
145                            if let Some(sv) = svs.last() { obj.floor_identification = sv.clone(); }
146                        }
147                        _ => {}
148                    }
149                }
150                "StreetDetail.name" => {
151                    match val {
152                        crate::base::FieldValue::Text(sv) => { obj.name = sv.clone(); }
153                        crate::base::FieldValue::TextList(svs) => {
154                            if let Some(sv) = svs.last() { obj.name = sv.clone(); }
155                        }
156                        _ => {}
157                    }
158                }
159                "StreetDetail.number" => {
160                    match val {
161                        crate::base::FieldValue::Text(sv) => { obj.number = sv.clone(); }
162                        crate::base::FieldValue::TextList(svs) => {
163                            if let Some(sv) = svs.last() { obj.number = sv.clone(); }
164                        }
165                        _ => {}
166                    }
167                }
168                "StreetDetail.prefix" => {
169                    match val {
170                        crate::base::FieldValue::Text(sv) => { obj.prefix = sv.clone(); }
171                        crate::base::FieldValue::TextList(svs) => {
172                            if let Some(sv) = svs.last() { obj.prefix = sv.clone(); }
173                        }
174                        _ => {}
175                    }
176                }
177                "StreetDetail.suffix" => {
178                    match val {
179                        crate::base::FieldValue::Text(sv) => { obj.suffix = sv.clone(); }
180                        crate::base::FieldValue::TextList(svs) => {
181                            if let Some(sv) = svs.last() { obj.suffix = sv.clone(); }
182                        }
183                        _ => {}
184                    }
185                }
186                "StreetDetail.suiteNumber" => {
187                    match val {
188                        crate::base::FieldValue::Text(sv) => { obj.suite_number = sv.clone(); }
189                        crate::base::FieldValue::TextList(svs) => {
190                            if let Some(sv) = svs.last() { obj.suite_number = sv.clone(); }
191                        }
192                        _ => {}
193                    }
194                }
195                "StreetDetail.type" => {
196                    match val {
197                        crate::base::FieldValue::Text(sv) => { obj.type_ = sv.clone(); }
198                        crate::base::FieldValue::TextList(svs) => {
199                            if let Some(sv) = svs.last() { obj.type_ = sv.clone(); }
200                        }
201                        _ => {}
202                    }
203                }
204                "StreetDetail.withinTownLimits" => {
205                    match val {
206                        crate::base::FieldValue::Text(sv) => { obj.within_town_limits = Some(sv.trim() == "true"); }
207                        crate::base::FieldValue::TextList(svs) => {
208                            if let Some(sv) = svs.last() { obj.within_town_limits = Some(sv.trim() == "true"); }
209                        }
210                        _ => {}
211                    }
212                }
213                _ => {}
214            }
215        }
216        obj
217    }
218}