diff options
author | jan <jan@ruken.pw> | 2016-10-09 09:28:08 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-10-09 09:28:08 (UTC) |
commit | 6d7a31be9c6fd413d407334c40d02c008b7334ec (patch) | |
tree | b9e73e5651d2dc1d72833875ab37469b7f2c1b53 /src/character.rs | |
parent | 54c2cb1e484e09b4fcfe236aff70c01bf3bbaae0 (diff) |
fixierung
Diffstat (limited to 'src/character.rs')
-rw-r--r-- | src/character.rs | 64 |
1 files changed, 46 insertions, 18 deletions
diff --git a/src/character.rs b/src/character.rs index 0630a45..f4686cf 100644 --- a/src/character.rs +++ b/src/character.rs | |||
@@ -42,19 +42,29 @@ pub struct Character { | |||
42 | 42 | ||
43 | impl Names { | 43 | impl Names { |
44 | pub fn new() -> Self { | 44 | pub fn new() -> Self { |
45 | Names { romaji: String::new(), japanese: String::new(), aliases: vec![] } | 45 | Names { |
46 | romaji: String::new(), | ||
47 | japanese: String::new(), | ||
48 | aliases: vec![], | ||
49 | } | ||
46 | } | 50 | } |
47 | } | 51 | } |
48 | 52 | ||
49 | impl Images { | 53 | impl Images { |
50 | pub fn new() -> Self { | 54 | pub fn new() -> Self { |
51 | Images { thumb: String::new(), full: String::new() } | 55 | Images { |
56 | thumb: String::new(), | ||
57 | full: String::new(), | ||
58 | } | ||
52 | } | 59 | } |
53 | } | 60 | } |
54 | 61 | ||
55 | impl Traits { | 62 | impl Traits { |
56 | pub fn new() -> Self { | 63 | pub fn new() -> Self { |
57 | Traits { official: vec![], indexed: vec![] } | 64 | Traits { |
65 | official: vec![], | ||
66 | indexed: vec![], | ||
67 | } | ||
58 | } | 68 | } |
59 | } | 69 | } |
60 | 70 | ||
@@ -67,13 +77,14 @@ impl Character { | |||
67 | traits: Traits::new(), | 77 | traits: Traits::new(), |
68 | assignments: vec![], | 78 | assignments: vec![], |
69 | extra: vec![], | 79 | extra: vec![], |
70 | role: None | 80 | role: None, |
71 | } | 81 | } |
72 | } | 82 | } |
73 | 83 | ||
74 | pub fn parse(&mut self, buf: &str) { | 84 | pub fn parse(&mut self, buf: &str) { |
75 | let re_extras = Regex::new(r#"(?is)Extra Details \| [0-9]+</H3>.*?<dl>(.*?)</dl>"#).unwrap(); | 85 | let re_extras = Regex::new(r#"(?is)Extra Details \| [0-9]+</H3>.*?<dl>(.*?)</dl>"#) |
76 | let mut sections = get_sections(); | 86 | .unwrap(); |
87 | let mut sections = get_sections(); | ||
77 | section::process(&buf, &mut sections); | 88 | section::process(&buf, &mut sections); |
78 | 89 | ||
79 | let caps = re_extras.captures(&buf); | 90 | let caps = re_extras.captures(&buf); |
@@ -89,40 +100,57 @@ impl Character { | |||
89 | 100 | ||
90 | self.name.romaji = name.data["romaji".into()].clone(); | 101 | self.name.romaji = name.data["romaji".into()].clone(); |
91 | self.name.japanese = name.data["japanese".into()].clone(); | 102 | self.name.japanese = name.data["japanese".into()].clone(); |
92 | 103 | ||
93 | if name.data["aliases".into()].len() > 0 { | 104 | if name.data["aliases".into()].len() > 0 { |
94 | self.name.aliases = name.data["aliases".into()].split(", ").map(|s| s.to_string()).collect(); | 105 | self.name.aliases = name.data["aliases".into()] |
106 | .split(", ") | ||
107 | .map(|s| s.to_string()) | ||
108 | .collect(); | ||
95 | } | 109 | } |
96 | 110 | ||
97 | self.image.thumb = image.data["thumb".into()].clone(); | 111 | self.image.thumb = image.data["thumb".into()].clone(); |
98 | self.image.full = image.data["full".into()].clone(); | 112 | self.image.full = image.data["full".into()].clone(); |
99 | 113 | ||
100 | if tags.data.contains_key("tags_raw".into()) { | 114 | if tags.data.contains_key("tags_raw".into()) { |
101 | self.tags = tags::parse(&tags.data["tags_raw".into()]); | 115 | self.tags = tags::parse(&tags.data["tags_raw".into()]); |
102 | } | 116 | } |
103 | 117 | ||
104 | self.traits.official = dl_list::parse(&(§ions["traits"] as &Section).data["official_raw".into()]); | 118 | self.traits.official = |
105 | self.traits.indexed = dl_list::parse(&(§ions["traits"] as &Section).data["indexed_raw".into()]); | 119 | dl_list::parse(&(§ions["traits"] as &Section).data["official_raw".into()]); |
120 | self.traits.indexed = | ||
121 | dl_list::parse(&(§ions["traits"] as &Section).data["indexed_raw".into()]); | ||
106 | 122 | ||
107 | self.assignments = tiles::parse_tile_link_ids(&(§ions["assignments"] as &Section).data["raw".into()], "series"); | 123 | self.assignments = tiles::parse_tile_link_ids(&(§ions["assignments"] as &Section).data["raw".into()], "series"); |
108 | 124 | ||
109 | if misc.data["role".into()].len() > 0 { | 125 | if misc.data["role".into()].len() > 0 { |
110 | self.role = Some(misc.data["role".into()].clone()); | 126 | self.role = Some(misc.data["role".into()].clone()); |
111 | } | 127 | } |
112 | } | 128 | } |
113 | } | 129 | } |
114 | } | 130 | } |
115 | 131 | ||
116 | fn get_sections() -> HashMap<String, Section> { | 132 | fn get_sections() -> HashMap<String, Section> { |
117 | let mut s: HashMap<String, Section> = HashMap::new(); | 133 | let mut s: HashMap<String, Section> = HashMap::new(); |
118 | 134 | ||
119 | s.insert("name".into(), Section::new("name", r#"(?is)Romaji Name.*?<TD>(.*?)\s?</TD>.*?Japanese Name.*?<TD>(.*?)\s?</TD>.*?Aliases.*?<TD>(.*?)\s?</TD>"#, vec!["romaji", "japanese", "aliases"])); | 135 | s.insert("name".into(), Section::new("name", r#"(?is)Romaji Name.*?<TD>(.*?)\s?</TD>.*?Japanese Name.*?<TD>(.*?)\s?</TD>.*?Aliases.*?<TD>(.*?)\s?</TD>"#, vec!["romaji", "japanese", "aliases"])); |
120 | s.insert("misc".into(), Section::new("misc", r#"(?is)Role</TH>.*?<TD>(.*?)\s?</TD>"#, vec!["role"])); | 136 | s.insert("misc".into(), |
137 | Section::new("misc", | ||
138 | r#"(?is)Role</TH>.*?<TD>(.*?)\s?</TD>"#, | ||
139 | vec!["role"])); | ||
121 | s.insert("image".into(), Section::new("image", r#"(?is)<H3 id="section99">.*<img src="(.*?)" alt=.*?></a><p><a href="(.*?)">View Full Size Image"#, vec!["thumb", "full"])); | 140 | s.insert("image".into(), Section::new("image", r#"(?is)<H3 id="section99">.*<img src="(.*?)" alt=.*?></a><p><a href="(.*?)">View Full Size Image"#, vec!["thumb", "full"])); |
122 | s.insert("tags".into(), Section::new("tags", r#"(?is)tagged as</P>.*?<TH>(.*?)</TH>"#, vec!["tags_raw"])); | 141 | s.insert("tags".into(), |
142 | Section::new("tags", | ||
143 | r#"(?is)tagged as</P>.*?<TH>(.*?)</TH>"#, | ||
144 | vec!["tags_raw"])); | ||
123 | s.insert("traits".into(), Section::new("traits", r#"(?is)indexed traits</P>.*?<dl>(.*?)</dl>.*?official traits\s?</P>.*?<dl>(.*?)</dl>"#, vec!["indexed_raw", "official_raw"])); | 145 | s.insert("traits".into(), Section::new("traits", r#"(?is)indexed traits</P>.*?<dl>(.*?)</dl>.*?official traits\s?</P>.*?<dl>(.*?)</dl>"#, vec!["indexed_raw", "official_raw"])); |
124 | s.insert("assignments".into(), Section::new("assignments", r#"(?is)appears in the following</P>(.*?)</UL>"#, vec!["raw"])); | 146 | s.insert("assignments".into(), |
125 | s.insert("chars_similar_traits".into(), Section::new("assignments", r#"(?is)with Similar Traits</H3>(.*?)</UL>"#, vec!["raw"])); | 147 | Section::new("assignments", |
148 | r#"(?is)appears in the following</P>(.*?)</UL>"#, | ||
149 | vec!["raw"])); | ||
150 | s.insert("chars_similar_traits".into(), | ||
151 | Section::new("assignments", | ||
152 | r#"(?is)with Similar Traits</H3>(.*?)</UL>"#, | ||
153 | vec!["raw"])); | ||
126 | 154 | ||
127 | s | 155 | s |
128 | } | 156 | } |