diff options
author | jan <jan@ruken.pw> | 2016-10-09 06:40:07 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-10-09 06:40:07 (UTC) |
commit | 54c2cb1e484e09b4fcfe236aff70c01bf3bbaae0 (patch) | |
tree | 3483753fb061d32f32bbe0c1a609d4b760192e47 /src/series.rs | |
parent | b8b1da0a95635fe9ed4ba28851906556ccc351a8 (diff) |
serien hinzugefuegt, aber ich muss auf die naechste rust nightly warten
Diffstat (limited to 'src/series.rs')
-rw-r--r-- | src/series.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/series.rs b/src/series.rs new file mode 100644 index 0000000..d111fb8 --- /dev/null +++ b/src/series.rs | |||
@@ -0,0 +1,63 @@ | |||
1 | use super::tags; | ||
2 | use super::tags::Tag; | ||
3 | use super::dl_list; | ||
4 | use super::dl_list::DLListItem; | ||
5 | use super::section; | ||
6 | use super::section::Section; | ||
7 | use super::regex::Regex; | ||
8 | use super::tiles; | ||
9 | |||
10 | use std::collections::HashMap; | ||
11 | |||
12 | #[derive(Debug, Serialize)] | ||
13 | pub struct Names { | ||
14 | pub english: String, | ||
15 | pub aliases: String, | ||
16 | pub romaji: String, | ||
17 | pub furigana: String, | ||
18 | pub japanese: String, | ||
19 | } | ||
20 | |||
21 | #[derive(Debug, Serialize)] | ||
22 | pub struct Series { | ||
23 | pub name: Names, | ||
24 | } | ||
25 | |||
26 | impl Names { | ||
27 | pub fn new() -> Self { | ||
28 | Names { | ||
29 | String::new(), String::new(), String::new(), String::new(), String::new() | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | |||
34 | impl Series { | ||
35 | pub fn new() -> Self { | ||
36 | Series { | ||
37 | name: Names::new() | ||
38 | } | ||
39 | } | ||
40 | |||
41 | pub fn parse(&mut self, buf: &str) { | ||
42 | let mut sections = get_sections(); | ||
43 | section::process(&buf, &mut sections); | ||
44 | |||
45 | { | ||
46 | let name: &Section = §ions["name".into()]; | ||
47 | |||
48 | self.name.english = name["english".into()]; | ||
49 | self.name.aliases = name["aliases".into()]; | ||
50 | self.name.romaji = name["romaji".into()]; | ||
51 | self.name.furigana = name["furigana".into()]; | ||
52 | self.name.japanese = name["japanese".into()]; | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | |||
57 | fn get_sections() -> HashMap<String, Section> { | ||
58 | let mut s: HashMap<String, Section> = HashMap::new(); | ||
59 | |||
60 | 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"])); | ||
61 | |||
62 | s | ||
63 | } | ||