Class: Kiba::Extend::Transforms::Helpers::OrgNameChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/transforms/helpers/org_name_checker.rb

Overview

Returns true/false indicating whether given value matches any given or added patterns. Used on a list of names and name-like values, this works ok. Used on a list of subject like terms or on freetext, be wary of false positives (though the patterns and the duplicative anchoring matching tries to avoid matching subject-like terms

Since:

  • 4.0.0

Constant Summary collapse

TERMS =

Since:

  • 4.0.0

<<~LIST
  (?:
  # business domains or types
  auto(motive|)|hotels?|inn|insurance|plumb(ers|ing)|roofing|shop|
  store|
  # clubs and groups
  association|club|fraternity|friends of the|legion|league|
  society|sorority|team|
  # corporate or company name terms
  company|consultant(s|)|corporation|group|incorporated|service|
  # education
  academy|college|institute|program|university|school|
  # events
  games|olympics|
  # food and drink
  brewer(ies|y)|cafe|farm|grocer(ies|y)|restaurant|saloon|tavern|
  # glam or cultural institutions
  band|centers?|choir|ensemble|gallery|library|museum|observatory|
  orchestra|studio|theat(er|re)|
  # governmental
  agency|court of|general assembly|senate|tribe|
  # health-related
  hospital|nursing home|pharmacy|
  # military
  artillery|brigade|infantry|regiment|
  # non-profity terms
  alliance|board of|foundation|program|task ?force|
  # organizational units
  administration|assembly|bureau|commission|committee|council|
  department|division|federation|office|
  # transportation
  airport|depot|rail(road|way)
  )
LIST
DEFAULT_PATTERNS =

Since:

  • 4.0.0

[
  / LLC/i,
  / co$/i,
  / corp$/i,
  /\bdept$/i,
  /\bdept\./i,
  /\binc$/i,
  /\binc\./i,
  /^\w+ (?:&|and) \w+$/,
  /^(\w+,? )+(?:&|and) \w+$/,
  /'s$/,
  /\b(inter|multi)?national\b/i,
  / (network|project|services?)$/i,
  /\.com$/,
  /publish/i,
  # term at beginning
  /^#{TERMS}\b.+/ix,
  # term between other terms
  /.+\b#{TERMS}\b.+/ix,
  # term at end
  /.+\b#{TERMS}$/ix
]
FAMILY_PATTERNS =

Since:

  • 4.0.0

[
  / famil(ies|y)/i
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(added_patterns: [], family_is_org: false) ⇒ OrgNameChecker

Returns a new instance of OrgNameChecker.

Parameters:

  • added_patterns (Array<Regexp>) (defaults to: [])

    non-standard regexp to check against. Best practice is to add these to this helper via a pull request if you think they generally indicate organization-ness

  • family_is_org (Boolean) (defaults to: false)

    whether names with terms indicating family-ness are treated as organizations (yes for CollectionSpace, no for applications that have a Family name type)

Since:

  • 4.0.0



97
98
99
100
# File 'lib/kiba/extend/transforms/helpers/org_name_checker.rb', line 97

def initialize(added_patterns: [], family_is_org: false)
  base = DEFAULT_PATTERNS + added_patterns
  @patterns = family_is_org ? base + FAMILY_PATTERNS : base
end

Class Method Details

.call(value:, added_patterns: [], family_is_org: false) ⇒ Object

Since:

  • 4.0.0



17
18
19
20
21
22
23
24
25
26
# File 'lib/kiba/extend/transforms/helpers/org_name_checker.rb', line 17

def call(
  value:,
  added_patterns: [],
  family_is_org: false
)
  new(
    added_patterns: added_patterns,
    family_is_org: family_is_org
  ).call(value)
end

Instance Method Details

#call(value) ⇒ true, false

Parameters:

  • value (String)

Returns:

  • (true)

    if value matches an org pattern

  • (false)

    otherwise

Since:

  • 4.0.0



105
106
107
108
109
110
111
# File 'lib/kiba/extend/transforms/helpers/org_name_checker.rb', line 105

def call(value)
  testval = value.sub(/\. *$/, "")
  return false if testval.blank?
  return true if patterns.any? { |pattern| testval.match?(pattern) }

  false
end