aboutsummaryrefslogtreecommitdiff
path: root/src/series.rs
blob: d111fb8120e4e86eefd04670ffbd608bdbb5c239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use super::tags;
use super::tags::Tag;
use super::dl_list;
use super::dl_list::DLListItem;
use super::section;
use super::section::Section;
use super::regex::Regex;
use super::tiles;

use std::collections::HashMap;

#[derive(Debug, Serialize)]
pub struct Names {
    pub english: String,
    pub aliases: String,
    pub romaji: String,
    pub furigana: String,
    pub japanese: String,
}

#[derive(Debug, Serialize)]
pub struct Series {
    pub name: Names,
}

impl Names {
    pub fn new() -> Self {
        Names {
            String::new(), String::new(), String::new(), String::new(), String::new()
        }
    }
}

impl Series {
    pub fn new() -> Self {
        Series {
            name: Names::new()
        }
    }

    pub fn parse(&mut self, buf: &str) {
        let mut sections = get_sections();    
        section::process(&buf, &mut sections);

        {
            let name: &Section = &sections["name".into()];

            self.name.english = name["english".into()];
            self.name.aliases = name["aliases".into()];
            self.name.romaji = name["romaji".into()];
            self.name.furigana = name["furigana".into()];
            self.name.japanese = name["japanese".into()];
        }
   }
}

fn get_sections() -> HashMap<String, Section> {
    let mut s: HashMap<String, Section> = HashMap::new();

    s.insert("name".into(), Section::new("name", r#"(?is)English Title.*?<TD>(.*?)</TD>.*?Aliases.*?<TD>(.*?)?</TD>.*?Romaji Title.*?<TD.*?>(.*?)</TD>.*?Furigana Title.*?<TD.*?>(.*?)</TD>.*?Japanese Title.*?<TD.*?>(.*?)</TD>"#, vec!["english", "aliases", "romaji", "furigana", "japanese"]));

    s
}