Class: Kiba::Extend::Transforms::Helpers::OrgNameChecker
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Helpers::OrgNameChecker
- 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
Constant Summary collapse
- TERMS =
<<~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 =
[ / 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 =
[ / famil(ies|y)/i ]
Class Method Summary collapse
Instance Method Summary collapse
-
#call(value) ⇒ true, false
-
#initialize(added_patterns: [], family_is_org: false) ⇒ OrgNameChecker
constructor
A new instance of OrgNameChecker.
Constructor Details
#initialize(added_patterns: [], family_is_org: false) ⇒ OrgNameChecker
Returns a new instance of OrgNameChecker.
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
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
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 |