warlocks_cauldron/providers/
development.rs

1use crate::Internet;
2
3use super::{Local, Datelike, dependencies::*};
4
5
6/// Methods collection for getting fake data for Developers
7pub struct Development;
8
9impl Development {
10    /// Generates a random DSN (Data Source Name)
11    ///
12    /// return example: postgres://some.host:5432
13    ///
14    /// # Arguments
15    /// * `tld_type` - DSNType provide service scheme and port
16    /// * `tld_type` - TLDType provide hostname domain
17    /// * `subdomains` - vec of subdomains
18    pub fn dsn(dsn_type: Option<DSNType>, tld_type: Option<TLDType>, subdomains: Option<Vec<&str>>) -> String {
19        let hostname = Internet::hostname(tld_type, subdomains);
20        let (scheme, port) = validate_enum(dsn_type, None);
21        format!("{scheme}://{hostname}:{port}")
22    }
23
24    /// Generate a random software license
25    ///
26    /// return example: GNU General Public License (GPL)
27    pub fn software_license() -> &'static str {
28        get_random_element(LICENSES.iter())
29    }
30
31    /// Generate version number
32    ///
33    /// return example: 6.6.6
34    /// 
35    /// # Arguments
36    /// * `calver` - ISBN format
37    /// * `pre_release` - Locale code from enum
38    pub fn version(calver: bool, pre_release: bool) -> String {
39        let (major, minor, patch) = match calver {
40            true => {
41                let now = Local::now().year();
42                (randint(now - 6, now), randint(1, 10), randint(1, 10))
43            },
44            false => (randint(1, 10), randint(1, 10), randint(1, 10)),
45        };
46
47        let version = format!("{major}.{minor}.{patch}");
48
49        if pre_release {
50            let suffix = get_random_element(vec!["alpha", "beta", "rc"].into_iter());
51            let number = randint(1, 11);
52            format!("{version}-{suffix}.{number}")
53        } else {
54            version
55        }
56    }
57
58    /// Get a random programming language
59    /// 
60    /// return example: Rust
61    pub fn programming_language() -> &'static str {
62        get_random_element(PROGRAMMING_LANGS.iter())
63    }
64
65    /// Get a random operating system or distributive name
66    /// 
67    /// return example: Windows 11
68    pub fn os() -> &'static str {
69        get_random_element(OS.iter())
70    }
71
72    /// Generate a random PIN code
73    /// 
74    /// return example: pin string
75    pub fn boolean() -> bool {
76        rand_bool(0.5)
77    }
78}