diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 19262b1..e1e95da 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -83,6 +83,36 @@ impl NumberParser { unique_contacts } + + + fn update_contacts(&self, contacts: &Vec) -> Vec { + let mut updated: Vec = 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"