packs/packs/parsing/ruby/
rails_utils.rs

1use std::{collections::HashSet, path::Path};
2
3use regex::Regex;
4
5// Load in config/initializers/inflections.rb
6// For any inflections in there, add them to the acronyms vector
7// An inflection takes the form of "inflect.acronym 'API'", so "API" would be the acronym here
8// This is a bit of a hack, but it's the easiest way to get the inflections loaded in
9// TODO: Figure out a better way to do this
10pub(crate) fn get_acronyms_from_disk(
11    inflections_path: &Path,
12) -> HashSet<String> {
13    let mut acronyms: HashSet<String> = HashSet::new();
14
15    if inflections_path.exists() {
16        let inflections_file =
17            std::fs::read_to_string(inflections_path).unwrap();
18        let inflections_lines = inflections_file.lines();
19        for line in inflections_lines {
20            if line.contains(".acronym") {
21                let re = Regex::new(r#"['\\"]"#).unwrap();
22                let acronym = re.split(line).nth(1).unwrap();
23                acronyms.insert(acronym.to_string());
24            }
25        }
26    }
27
28    acronyms
29}