warlocks_cauldron/providers/
path.rs

1use super::dependencies::*;
2
3
4/// Enum for init path-gen struct
5pub enum PlatformType { Win, Linux }
6
7impl PlatformType {
8    /// Detect current system platform
9    pub fn detect() -> Self {
10        match cfg!(windows) {
11            true => Self::Win,
12            false => Self::Linux,
13        }
14    }
15}
16
17/// Methods collection that provides methods and property for generate paths
18pub struct Path {
19    is_win: bool
20}
21
22impl Path {
23    /// Initialize path-gen with platfrom specify
24    pub fn new(platform: PlatformType) -> Self {
25        Self { 
26            is_win: match platform {
27                PlatformType::Win => true,
28                _ => false,
29            }
30        }
31    }
32
33    /// Generate path from paths
34    fn path_gen<const N: usize>(&self, paths: [&str; N]) -> String {
35        paths.iter().join(&self.delimetr())
36    }
37
38    /// Get path delimetr
39    pub fn delimetr(&self) -> String {
40        match self.is_win {
41            true => "\\",
42            false => "/",
43        }.to_string()
44    }
45
46    /// Generate a root dir path
47    pub fn root(&self) -> String {
48        match self.is_win {
49            true => "C:\\Windows",
50            false => "/",
51        }.to_string()
52    }
53
54    /// Generate a home path
55    pub fn home(&self) -> String {
56        match self.is_win {
57            true => "C:\\Users",
58            false => "/home",
59        }.to_string()
60    }
61
62    /// Generate a random user
63    pub fn user(&self) -> String {
64        let user = get_random_element(USERNAMES.iter());
65        match self.is_win {
66            true => user[..1].to_uppercase() + &user[1..],
67            false => user.to_string(),
68        }
69    }
70
71    /// Generate a random path to user's folders
72    pub fn users_folder(&self) -> String {
73        let folder = get_random_element(FOLDERS.iter());
74        self.path_gen([&self.home(), &self.user(), &folder])
75    }
76
77    /// Generate a random path to development directory
78    pub fn dev_dir(&self) -> String {
79        let folder = get_random_element(vec!["Development", "Dev"].into_iter());
80        let stack = get_random_element(PROGRAMMING_LANGS.iter());
81        self.path_gen([&self.home(),  &self.user(), folder, stack])
82    }
83
84    /// Generate a random path to project directory
85    pub fn project_dir(&self) -> String {
86        let project = get_random_element(PROJECT_NAMES.iter());
87        self.path_gen([&self.dev_dir(), project])
88    }
89}