warlocks_cauldron/providers/
finance.rs

1use super::dependencies::*;
2
3
4/// A struct for generating finance data
5pub struct Finance<'a>(pub &'a Locale);
6
7impl<'a> Finance<'a> {
8    /// Private. Return global parsed data from own locale
9    fn data(&self) -> &ParsedData { self.0.get_data() }
10
11    /// Get a random company name
12    ///
13    /// return example: Some Company He.Re.
14    pub fn company(&self) -> &str {
15        get_random_element(self.data().finance.company.name.iter())
16    }
17
18    /// Get a random type of business entity
19    ///
20    /// return example: Corp. OR Coproration
21    pub fn company_type(&self, abbr: bool) -> &str {
22        get_random_element(match abbr {
23            true => self.data().finance.company._type.abbr.iter(),
24            false => self.data().finance.company._type.title.iter(),
25        })
26    }
27
28    /// Get code of the currency for current locale
29    ///
30    /// return example: USD
31    /// 
32    /// # Arguments
33    /// * `allow_random` - Get a random ISO code
34    pub fn currency_iso_code(&self, allow_random: bool) -> &str {
35        match allow_random {
36            true => get_random_element(CURRENCY_ISO_CODES.iter()),
37            false => &self.data().finance.currency_code,
38        }
39    }
40
41    /// Get a cryptocurrency symbol
42    /// 
43    /// return example: BTC
44    pub fn cryptocurrency_iso_code() -> &'static str {
45        get_random_element(CRYPTOCURRENCY_ISO_CODES.iter())
46    }
47
48    /// Get a currency symbol for current locale
49    /// 
50    /// return example: $
51    pub fn currency_symbol(&self) -> &str {
52        CURRENCY_SYMBOLS.get(self.data().lang_code.as_str()).unwrap_or_else(|| CURRENCY_SYMBOLS.get("default").unwrap())
53    }
54
55    /// Get a cryptocurrency symbol
56    /// 
57    /// return example: ₿
58    pub fn cryptocurrency_symbol() -> &'static str {
59        get_random_element(CRYPTOCURRENCY_SYMBOLS.iter())
60    }
61
62
63    /// Generate random price
64    /// 
65    /// return example: 6.66
66    /// 
67    /// # Arguments
68    /// * `minimum` - minimum value of price
69    /// * `maximum` - maximum value of price
70    pub fn price(minimum: f32, maximum: f32) -> f32 {
71        uniform(minimum, maximum)
72    }
73
74    /// Return random stock ticker
75    /// 
76    /// return example: ABC
77    pub fn stock_ticker() -> &'static str {
78        get_random_element(STOCK_TICKERS.iter())
79    }
80
81    /// Return stock name
82    /// 
83    /// return example: 1-800 FLOWERS.COM
84    pub fn stock_name() -> &'static str {
85        get_random_element(STOCK_NAMES.iter())
86    }
87
88    /// Returns stock exchange name
89    /// 
90    /// return example: NASDAQ
91    pub fn stock_exchange() -> &'static str {
92        get_random_element(STOCK_EXCHANGES.iter())
93    }
94}