parse index
This commit is contained in:
parent
7bd717e4db
commit
674eba3fd0
2 changed files with 49 additions and 3 deletions
|
|
@ -18,7 +18,9 @@ pub enum EditionBlock {
|
|||
pub enum EditionCode {
|
||||
/// Sword and Shield
|
||||
Ssh,
|
||||
/// Scarlet and Violer
|
||||
/// SV Promos
|
||||
Svp,
|
||||
/// Scarlet and Violet
|
||||
Svi,
|
||||
/// Paldea Evolved
|
||||
Pal,
|
||||
|
|
@ -42,6 +44,14 @@ pub enum EditionCode {
|
|||
Ssp,
|
||||
/// Prismatic Evolutions
|
||||
Pre,
|
||||
/// Journey Together
|
||||
Jtg,
|
||||
/// Destined Rivals
|
||||
Dri,
|
||||
/// Black Bolt
|
||||
Blk,
|
||||
/// White Flare
|
||||
Wht,
|
||||
/// Mega Evolution
|
||||
Meg,
|
||||
/// Phantasmal Flames
|
||||
|
|
@ -52,6 +62,7 @@ impl EditionCode {
|
|||
pub fn edition_num(self) -> &'static str {
|
||||
match self {
|
||||
EditionCode::Ssh => "SWSH1",
|
||||
EditionCode::Svp => "SVP",
|
||||
EditionCode::Svi => "SV01",
|
||||
EditionCode::Pal => "SV02",
|
||||
EditionCode::Obf => "SV03",
|
||||
|
|
@ -64,6 +75,10 @@ impl EditionCode {
|
|||
EditionCode::Scr => "SV07",
|
||||
EditionCode::Ssp => "SV08",
|
||||
EditionCode::Pre => "SV8pt5",
|
||||
EditionCode::Jtg => "SV9",
|
||||
EditionCode::Dri => "SV10",
|
||||
EditionCode::Blk => "SV10pt5ZSV",
|
||||
EditionCode::Wht => "SV10pt5RSV",
|
||||
EditionCode::Meg => "MEG1",
|
||||
EditionCode::Pfl => "MEG2",
|
||||
}
|
||||
|
|
@ -73,6 +88,7 @@ impl EditionCode {
|
|||
match self {
|
||||
EditionCode::Ssh => "sword-shield",
|
||||
EditionCode::Svi => "scarlet-violet",
|
||||
EditionCode::Svp => "scarlet-violet-promos",
|
||||
EditionCode::Pal => "paldea-evolved",
|
||||
EditionCode::Obf => "obsidian-flames",
|
||||
EditionCode::Mew => "151",
|
||||
|
|
@ -84,6 +100,9 @@ impl EditionCode {
|
|||
EditionCode::Scr => "stellar-crown",
|
||||
EditionCode::Ssp => "surging-sparks",
|
||||
EditionCode::Pre => "prismatic-evolutions",
|
||||
EditionCode::Jtg => "journey-together",
|
||||
EditionCode::Dri => "destined-rivals",
|
||||
EditionCode::Blk | EditionCode::Wht => "black-white",
|
||||
EditionCode::Meg => "mega-evolution",
|
||||
EditionCode::Pfl => "phantasmal-flames",
|
||||
}
|
||||
|
|
@ -93,6 +112,7 @@ impl EditionCode {
|
|||
match self {
|
||||
EditionCode::Ssh => EditionBlock::Ssh,
|
||||
EditionCode::Svi
|
||||
| EditionCode::Svp
|
||||
| EditionCode::Pal
|
||||
| EditionCode::Obf
|
||||
| EditionCode::Mew
|
||||
|
|
@ -103,7 +123,11 @@ impl EditionCode {
|
|||
| EditionCode::Sfa
|
||||
| EditionCode::Scr
|
||||
| EditionCode::Ssp
|
||||
| EditionCode::Pre => EditionBlock::Sv,
|
||||
| EditionCode::Pre
|
||||
| EditionCode::Jtg
|
||||
| EditionCode::Dri
|
||||
| EditionCode::Blk
|
||||
| EditionCode::Wht => EditionBlock::Sv,
|
||||
EditionCode::Meg | EditionCode::Pfl => EditionBlock::Meg,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
//! Models for malie.io exports
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, de};
|
||||
|
||||
use crate::editions::EditionCode;
|
||||
|
||||
|
|
@ -29,5 +31,25 @@ pub enum Lang {
|
|||
#[derive(Debug, Deserialize)]
|
||||
pub struct Edition {
|
||||
path: String,
|
||||
#[serde(deserialize_with = "deserialize_edition_code")]
|
||||
abbr: Option<EditionCode>,
|
||||
}
|
||||
|
||||
fn deserialize_edition_code<'de, D>(deserializer: D) -> Result<Option<EditionCode>, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
{
|
||||
let buf = Cow::<'de, str>::deserialize(deserializer)?;
|
||||
|
||||
if buf.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let buf = if buf.to_uppercase() == "PR-SV" {
|
||||
"SVP".into()
|
||||
} else {
|
||||
buf
|
||||
};
|
||||
|
||||
Ok(EditionCode::from_str(&buf).ok())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue