aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-10-09 06:40:07 (UTC)
committerjan <jan@ruken.pw>2016-10-09 06:40:07 (UTC)
commit54c2cb1e484e09b4fcfe236aff70c01bf3bbaae0 (patch)
tree3483753fb061d32f32bbe0c1a609d4b760192e47 /src
parentb8b1da0a95635fe9ed4ba28851906556ccc351a8 (diff)
serien hinzugefuegt, aber ich muss auf die naechste rust nightly warten
Diffstat (limited to 'src')
-rw-r--r--src/main.rs6
-rw-r--r--src/series.rs63
2 files changed, 67 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 2b96024..7481376 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,4 @@
1#![feature(rustc_macro)] 1#![feature(proc_macro)]
2#[macro_use] extern crate serde_derive; 2#[macro_use] extern crate serde_derive;
3extern crate serde_json; 3extern crate serde_json;
4 4
@@ -22,6 +22,8 @@ mod section;
22 22
23mod character; 23mod character;
24use character::Character; 24use character::Character;
25mod series;
26use series::Series;
25 27
26mod tags; 28mod tags;
27mod dl_list; 29mod dl_list;
@@ -66,7 +68,7 @@ fn main() {
66 68
67 let buf = pre_process::strip_irrelevant_content(&buf); 69 let buf = pre_process::strip_irrelevant_content(&buf);
68 70
69 let mut char = Character::new(); 71 let mut char = Series::new();
70 char.parse(&buf); 72 char.parse(&buf);
71 73
72 let json = serde_json::to_string(&char).unwrap(); 74 let json = serde_json::to_string(&char).unwrap();
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 @@
1use super::tags;
2use super::tags::Tag;
3use super::dl_list;
4use super::dl_list::DLListItem;
5use super::section;
6use super::section::Section;
7use super::regex::Regex;
8use super::tiles;
9
10use std::collections::HashMap;
11
12#[derive(Debug, Serialize)]
13pub 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)]
22pub struct Series {
23 pub name: Names,
24}
25
26impl Names {
27 pub fn new() -> Self {
28 Names {
29 String::new(), String::new(), String::new(), String::new(), String::new()
30 }
31 }
32}
33
34impl 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 = &sections["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
57fn 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}