Added updated_contacts method
Rust Build / Test Suite (pull_request) Failing after 56s
Rust Build / Check (pull_request) Failing after 33s
Rust Build / Rustfmt (pull_request) Failing after 33s
Rust Build / Clippy (pull_request) Failing after 51s
Rust Build / build (pull_request) Failing after 52s
Rust Build / Test Suite (pull_request) Failing after 56s
Rust Build / Check (pull_request) Failing after 33s
Rust Build / Rustfmt (pull_request) Failing after 33s
Rust Build / Clippy (pull_request) Failing after 51s
Rust Build / build (pull_request) Failing after 52s
This commit is contained in:
+30
-44
@@ -83,6 +83,36 @@ impl NumberParser {
|
||||
|
||||
unique_contacts
|
||||
}
|
||||
|
||||
|
||||
fn update_contacts(&self, contacts: &Vec<textsender_models::contact::Contact>) -> Vec<textsender_models::contact::Contact> {
|
||||
let mut updated: Vec<textsender_models::contact::Contact> = Vec::new();
|
||||
|
||||
for ct in contacts {
|
||||
let phone_number = ct.phone_number.clone();
|
||||
if phone_number.len() < 2 {
|
||||
println!("Invalid number: {phone_number:?}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// pars := prsr.removeSomeData(parsed)
|
||||
let pars = self.remove_some_data(&phone_number);
|
||||
// parsed = pars
|
||||
|
||||
println!("Parsed: {pars:?}");
|
||||
|
||||
// updatedParsed := prsr.addPrefix(parsed)
|
||||
let updated_parsed = self.add_prefix(&pars);
|
||||
// updated = append(updated, contact.Contact{PhoneNumber: updatedParsed})
|
||||
let contact = textsender_models::contact::Contact {
|
||||
phone_number: updated_parsed,
|
||||
..Default::default()
|
||||
};
|
||||
updated.push(contact);
|
||||
}
|
||||
|
||||
updated
|
||||
}
|
||||
|
||||
fn add_prefix(&self, raw: &String) -> String {
|
||||
let mut parsed: String = String::new();
|
||||
@@ -123,50 +153,6 @@ impl NumberParser {
|
||||
|
||||
|
||||
/*
|
||||
func (prsr *NumberParser) FileDump() []contact.Contact {
|
||||
log.Println("Dumping files")
|
||||
objs := []contact.Contact{}
|
||||
|
||||
for _, line := range prsr.readLines(prsr.FilePath) {
|
||||
if strings.ContainsAny(line, Letters) {
|
||||
continue
|
||||
}
|
||||
|
||||
myObj := contact.Contact{PhoneNumber: line}
|
||||
if myObj.PhoneNumber != "" {
|
||||
objs = append(objs, myObj)
|
||||
}
|
||||
}
|
||||
|
||||
objs = prsr.updateContacts(objs)
|
||||
objs = prsr.removeDups(objs)
|
||||
|
||||
return objs
|
||||
}
|
||||
|
||||
func (prsr *NumberParser) updateContacts(contacts []contact.Contact) []contact.Contact {
|
||||
updated := []contact.Contact{}
|
||||
|
||||
for _, ct := range contacts {
|
||||
parsed := ct.PhoneNumber
|
||||
if len(parsed) < 2 {
|
||||
log.Println("Invalid number:", parsed)
|
||||
continue
|
||||
}
|
||||
|
||||
pars := prsr.removeSomeData(parsed)
|
||||
parsed = pars
|
||||
|
||||
log.Println("Parsed:", parsed)
|
||||
|
||||
updatedParsed := prsr.addPrefix(parsed)
|
||||
updated = append(updated, contact.Contact{PhoneNumber: updatedParsed})
|
||||
}
|
||||
|
||||
return updated
|
||||
}
|
||||
|
||||
|
||||
func (prsr NumberParser) SaveFile(vals []contact.Contact) {
|
||||
filename := "numbers.json"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user