1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use super::dependencies::*;


/// Methods collection which provides methods for generating codes
pub struct Code;

impl Code {
    /// Get a random locale code (MS-LCID)
    ///
    /// return example: ru
    pub fn locale_code() -> &'static str {
        get_random_element(LOCALE_CODES.iter())
    }

    /// Generate a random ISSN
    ///
    /// return example: 1313-6666
    pub fn issn() -> String {
        custom_code("####-####", '@', '#')
    }

    /// Generate ISBN for current locale
    ///
    /// return example: isbn formatted string
    /// 
    /// # Arguments
    /// * `fmt` - ISBN format
    /// * `locale` - Locale code from enum
    pub fn isbn(fmt: Option<ISBNFormat>, locale: Locale) -> String {
        let data = locale.get_data();

        let fmt_key = validate_enum(fmt, None);

        let mask = ISBN_MASKS.get(fmt_key).expect("ISBN_MASKS doesnt have current ISBNFormat!")
            .replace("{0}", ISBN_GROUPS.get(&data.lang_code[..]).unwrap_or_else(|| ISBN_GROUPS.get("default").unwrap()));

        custom_code(&mask, '@', '#')
    }

    /// Generate EAN
    /// 
    /// return example: ean formatted string
    /// 
    /// # Arguments
    /// * `fmt` - Format of EAN
    pub fn ean(fmt: Option<EANFormat>) -> String {
        custom_code(EAN_MASKS.get(validate_enum(fmt, None)).expect("EAN_MASKS doesnt have current EANFormat!"), '@', '#')
    }

    /// Generate a random IMEI
    /// 
    /// return example: imei string
    pub fn imei() -> String {
        let num = format!("{}{}", get_random_element(IMEI_TACS.iter()), randint(100000, 999999));
        format!("{num}{}", luhn::checksum(num.as_bytes()))
    }

    /// Generate a random PIN code
    /// 
    /// return example: pin string
    pub fn pin() -> String {
        custom_code("####", '@', '#')
    }
}