Class: Kiba::Extend::Transforms::Name::ConvertInvertedToDirectForm
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Name::ConvertInvertedToDirectForm
- Defined in:
- lib/kiba/extend/transforms/name/convert_inverted_to_direct_form.rb
Overview
Note:
Makes many egregiously oversimplified Western assumptions. Do not trust it to split all names properly in all cases. Handles only the most common English language name patterns.
Splits an inverted name form into name parts and uses the parts to form a direct-entry name
Examples
In these examples, you can see the inverted name in the :iname
field of each row.
Used in pipeline as:
transform Name::ConvertInvertedToDirectForm, source: :iname, target: :direct
Results in:
{:iname=>"Smith, Robert", :firstname=>"Robert", :middlename=>nil, :lastname=>"Smith", :suffix=>nil, :direct=>"Robert Smith"}
{:iname=>"Smith, Robert J.", :firstname=>"Robert", :middlename=>"J.", :lastname=>"Smith", :suffix=>nil, :direct=>"Robert J. Smith"}
{:iname=>"Smith-Jones, Robert J.", :firstname=>"Robert", :middlename=>"J.", :lastname=>"Smith-Jones", :suffix=>nil, :direct=>"Robert J. Smith-Jones"}
{:iname=>"Smith, Robert James", :firstname=>"Robert", :middlename=>"James", :lastname=>"Smith", :suffix=>nil, :direct=>"Robert James Smith"}
{:iname=>"Smith, R. James", :firstname=>"R.", :middlename=>"James", :lastname=>"Smith", :suffix=>nil, :direct=>"R. James Smith"}
{:iname=>"Smith, Robert (Bob)", :firstname=>"Robert", :middlename=>"(Bob)", :lastname=>"Smith", :suffix=>nil, :direct=>"Robert (Bob) Smith"}
{:iname=>"Smith, Robert James (Bob)", :firstname=>"Robert", :middlename=>"James (Bob)", :lastname=>"Smith", :suffix=>nil, :direct=>"Robert James (Bob) Smith"}
{:iname=>"Smith, R. J.", :firstname=>"R.", :middlename=>"J.", :lastname=>"Smith", :suffix=>nil, :direct=>"R. J. Smith"}
{:iname=>"Smith, R.J.", :firstname=>"R.", :middlename=>"J.", :lastname=>"Smith", :suffix=>nil, :direct=>"R. J. Smith"}
{:iname=>"Smith, R J", :firstname=>"R", :middlename=>"J", :lastname=>"Smith", :suffix=>nil, :direct=>"R J Smith"}
{:iname=>"Smith, RJ", :firstname=>"R", :middlename=>"J", :lastname=>"Smith", :suffix=>nil, :direct=>"R J Smith"}
{:iname=>"Smith, RJR", :firstname=>"R", :middlename=>"JR", :lastname=>"Smith", :suffix=>nil, :direct=>"R JR Smith"}
{:iname=>"Smith, RJRR", :firstname=>"RJRR", :middlename=>nil, :lastname=>"Smith", :suffix=>nil, :direct=>"RJRR Smith"}
{:iname=>"Smith, R.", :firstname=>"R.", :middlename=>nil, :lastname=>"Smith", :suffix=>nil, :direct=>"R. Smith"}
{:iname=>"Smith", :firstname=>nil, :middlename=>nil, :lastname=>nil, :suffix=>nil, :direct=>"Smith"}
{:iname=>"Smith, Robert, Jr.", :firstname=>"Robert", :middlename=>nil, :lastname=>"Smith", :suffix=>"Jr.", :direct=>"Robert Smith, Jr."}
{:iname=>"Smith, R.J., Sr.", :firstname=>"R.", :middlename=>"J.", :lastname=>"Smith", :suffix=>"Sr.", :direct=>"R. J. Smith, Sr."}
{:iname=>"Smith, R. J., Sr.", :firstname=>"R.", :middlename=>"J.", :lastname=>"Smith", :suffix=>"Sr.", :direct=>"R. J. Smith, Sr."}
{:iname=>"R.J. Smith & Co.", :firstname=>nil, :middlename=>nil, :lastname=>nil, :suffix=>nil, :direct=>"R.J. Smith & Co."}
{:iname=>"Smith, James, Robert & Co.", :firstname=>"James", :middlename=>nil, :lastname=>"Smith", :suffix=>"Robert & Co.", :direct=>"James Smith, Robert & Co."}
{:iname=>"Robert \"Bob\" Smith", :firstname=>nil, :middlename=>nil, :lastname=>nil, :suffix=>nil, :direct=>"Robert \"Bob\" Smith"}
{:iname=>"", :firstname=>nil, :middlename=>nil, :lastname=>nil, :suffix=>nil, :direct=>""}
{:iname=>nil, :firstname=>nil, :middlename=>nil, :lastname=>nil, :suffix=>nil, :direct=>nil}
{:foo=>"bar", :firstname=>nil, :middlename=>nil, :lastname=>nil, :suffix=>nil, :direct=>nil}
Used in pipeline as:
transform Name::ConvertInvertedToDirectForm, source: :iname, target: :direct, nameparts: %i[f m l s]
Results in:
{:iname=>"Smith, R.J., Sr.", :direct=>"R. J. Smith, Sr.", :f=>"R.", :l=>"Smith", :m=>"J.", :s=>"Sr."}
Used in pipeline as:
transform Name::ConvertInvertedToDirectForm, source: :iname, target: :direct, keep_parts: false
Results in:
{:iname=>"Smith, R.J., Sr.", :direct=>"R. J. Smith, Sr."}
Instance Method Summary collapse
-
#initialize(source:, target:, nameparts: %i[firstname middlename lastname suffix], keep_parts: true) ⇒ ConvertInvertedToDirectForm
constructor
A new instance of ConvertInvertedToDirectForm.
-
#process(row) ⇒ Object
Constructor Details
#initialize(source:, target:, nameparts: %i[firstname middlename lastname suffix], keep_parts: true) ⇒ ConvertInvertedToDirectForm
Returns a new instance of ConvertInvertedToDirectForm.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/kiba/extend/transforms/name/convert_inverted_to_direct_form.rb', line 83 def initialize(source:, target:, nameparts: %i[firstname middlename lastname suffix], keep_parts: true) @source = source @target = target @nameparts = nameparts @firstname = nameparts[0] @middlename = nameparts[1] @lastname = nameparts[2] @suffix = nameparts[3] @keep_parts = keep_parts @convert_getter = Helpers::FieldValueGetter.new(fields: [firstname, middlename, lastname]) @convertable_getter = Helpers::FieldValueGetter.new(fields: nameparts) @splitter = Name::SplitInverted.new(source: source, targets: nameparts) end |
Instance Method Details
#process(row) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/kiba/extend/transforms/name/convert_inverted_to_direct_form.rb', line 102 def process(row) splitter.process(row) if convertable?(row) convert(row) else do_not_convert(row) end nameparts.each { |field| row.delete(field) } unless keep_parts row end |