module AccountNameKeyBuilder

Overview

Build a plain match key from account names, so that "Alpha Widgets Inc", "Alpha Widgets, LLC" and "The Alpha Widgets Company" show up as one group. The key only helps you SEE possible duplicates. It merges nothing, and two different companies can share a key.

Defined in:

account_name_key_builder.cr

Constant Summary

DEFAULT_SUFFIXES = ["inc", "incorporated", "llc", "ltd", "limited", "gmbh", "corp", "corporation", "co", "company", "plc", "pte", "bv", "ag", "sa"] of ::String

Default suffix list, replaced as a whole by --suffixes. Set by you.

REQUIRED = ["account_id", "name"] of ::String
USAGE = "usage: account-name-key-builder accounts.csv [--suffixes inc,llc,ltd]\nCSV columns: account_id, name. The key only helps you see possible duplicates; it merges nothing and two different companies can share a key. --suffixes replaces the default suffix list and is set by you.\nMore: https://www.onegtmlab.dev/tool-directory/data-platforms/clay"
VERSION = "1.0.0"

Class Method Summary

Class Method Detail

def self.cli(args : Array(String), stdout : IO, stderr : IO) : Int32 #

Command line entry. Returns the exit code: 0 ok, 1 bad input or file, 2 usage.


[View source]
def self.groups(accounts : Array(Account)) : Array(Group) #

Every key with its accounts in input order.


[View source]
def self.key(name : String, suffixes : Array(String) = DEFAULT_SUFFIXES) : String #

The key rule, in this exact order:

  1. lowercase
  2. "&" becomes " and "
  3. every character that is not a to z or 0 to 9 becomes a space (accented letters are therefore dropped, not transliterated)
  4. collapse spaces
  5. remove a leading word "the"
  6. repeatedly remove a trailing word that is in the suffix list

[View source]
def self.parse_csv(text : String) : Array(Array(String)) #

Small CSV reader: comma separated, double quoted fields may hold commas, line breaks and "" for a quote mark. Returns rows of raw cell strings.


[View source]
def self.parse_suffixes(text : String) : Array(String) #

Parse the --suffixes value: comma separated, trimmed, lowercased. Replaces the default list.


[View source]
def self.read_accounts(text : String, suffixes : Array(String) = DEFAULT_SUFFIXES) : Array(Account) #

[View source]
def self.render(accounts : Array(Account), suffixes : Array(String)) : String #

[View source]