-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add conversion of project - discipline (ongoing)
- Loading branch information
Showing
5 changed files
with
207 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::domain::value::iso_code::IsoCode; | ||
use crate::domain::value::LangString; | ||
use hcl::Attribute; | ||
use std::collections::HashMap; | ||
|
||
/// The discipline of a project can be defined in two ways: | ||
/// 1. A reference to a discipline defined in an external reference system (e.g. SNF or SKOS) | ||
/// 2. A text description of the discipline | ||
/// | ||
/// Example: | ||
/// ```hcl | ||
/// discipline skos { | ||
/// ref_id = "https://skos.um.es/unesco6/5501" | ||
/// description = "Local history" | ||
/// url = "https://skos.um.es/unesco6/5501" | ||
/// } | ||
/// ``` | ||
/// would be represented as: | ||
/// ```rust | ||
/// use dsp_meta::domain::value::Discipline; | ||
/// use dsp_meta::domain::value::Ref; | ||
/// use std::collections::HashMap; | ||
/// use url::Url; | ||
/// Discipline::Snf(Ref{ | ||
/// ref_id: "https://skos.um.es/unesco6/5501".to_string(), | ||
/// description: "Local history".to_string(), | ||
/// url: Url::parse("https://skos.um.es/unesco6/5501").unwrap(), | ||
/// }) | ||
/// ``` | ||
#[derive(Debug, PartialEq)] | ||
pub enum Discipline { | ||
Skos { | ||
ref_id: String, | ||
description: String, | ||
url: url::Url, | ||
}, | ||
Snf { | ||
ref_id: String, | ||
description: String, | ||
url: url::Url, | ||
}, | ||
Text(HashMap<IsoCode, String>), | ||
} | ||
|
||
impl TryFrom<Vec<&hcl::Attribute>> for Discipline { | ||
type Error = (); | ||
|
||
fn try_from(value: Vec<&Attribute>) -> Result<Self, Self::Error> { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::errors::DspMetaError; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
/// Language codes according to ISO 639-1 | ||
/// Not an exhaustive list. | ||
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)] | ||
pub enum IsoCode { | ||
#[default] | ||
DE, // German | ||
EN, // English | ||
FR, // French | ||
IT, // Italian | ||
ES, // Spanish | ||
PT, // Portuguese | ||
NL, // Dutch | ||
PL, // Polish | ||
RU, // Russian | ||
JA, // Japanese | ||
ZH, // Chinese | ||
AR, // Arabic | ||
FA, // Persian | ||
} | ||
|
||
impl Display for IsoCode { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
IsoCode::DE => write!(f, "de"), | ||
IsoCode::EN => write!(f, "en"), | ||
IsoCode::FR => write!(f, "fr"), | ||
IsoCode::IT => write!(f, "it"), | ||
IsoCode::ES => write!(f, "es"), | ||
IsoCode::PT => write!(f, "pt"), | ||
IsoCode::NL => write!(f, "nl"), | ||
IsoCode::PL => write!(f, "pl"), | ||
IsoCode::RU => write!(f, "ru"), | ||
IsoCode::JA => write!(f, "ja"), | ||
IsoCode::ZH => write!(f, "zh"), | ||
IsoCode::AR => write!(f, "ar"), | ||
IsoCode::FA => write!(f, "fa"), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<&str> for IsoCode { | ||
type Error = DspMetaError; | ||
|
||
fn try_from(value: &str) -> Result<Self, Self::Error> { | ||
match value { | ||
"de" => Ok(IsoCode::DE), | ||
"en" => Ok(IsoCode::EN), | ||
"fr" => Ok(IsoCode::FR), | ||
"it" => Ok(IsoCode::IT), | ||
"es" => Ok(IsoCode::ES), | ||
"pt" => Ok(IsoCode::PT), | ||
"nl" => Ok(IsoCode::NL), | ||
"pl" => Ok(IsoCode::PL), | ||
"ru" => Ok(IsoCode::RU), | ||
"ja" => Ok(IsoCode::JA), | ||
"zh" => Ok(IsoCode::ZH), | ||
"ar" => Ok(IsoCode::AR), | ||
"fa" => Ok(IsoCode::FA), | ||
_ => Err(DspMetaError::CreateValueObject( | ||
"Creating an IsoCode failed because provided value is not allowed.".to_string(), | ||
)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters