easyofd_reader/keyword/
keyword_resource.rs1#[derive(Debug, Clone)]
12pub struct KeywordResource {
13 pub page: usize,
15 pub font_id: Option<String>,
17 pub font_size: Option<f64>,
19}
20
21impl KeywordResource {
22 #[must_use]
24 pub fn new(page: usize) -> Self {
25 Self {
26 page,
27 font_id: None,
28 font_size: None,
29 }
30 }
31
32 #[must_use]
34 pub fn with_font_id(mut self, font_id: impl Into<String>) -> Self {
35 self.font_id = Some(font_id.into());
36 self
37 }
38
39 #[must_use]
41 pub fn with_font_size(mut self, size: f64) -> Self {
42 self.font_size = Some(size);
43 self
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_keyword_resource_new() {
53 let res = KeywordResource::new(1);
54 assert_eq!(res.page, 1);
55 assert!(res.font_id.is_none());
56 assert!(res.font_size.is_none());
57 }
58
59 #[test]
60 fn test_keyword_resource_with_font() {
61 let res = KeywordResource::new(2)
62 .with_font_id("font_0")
63 .with_font_size(12.0);
64 assert_eq!(res.font_id.as_deref(), Some("font_0"));
65 assert!((res.font_size.unwrap() - 12.0).abs() < f64::EPSILON);
66 }
67}