This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from SumOfUs/first-last-full-name-connection
Hack to make full_name and first/last name play together nicely.
- Loading branch information
Showing
7 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ def action_params | |
end | ||
|
||
def base_params | ||
%w{page_id form_id} | ||
%w{page_id form_id name} | ||
end | ||
|
||
def fields | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class NameSplitter | ||
def initialize(full_name:) | ||
@full_name = full_name | ||
@split_name = @full_name.split | ||
end | ||
|
||
def first_name | ||
@first_name || find_first_name | ||
end | ||
|
||
def last_name | ||
@last_name || find_last_name | ||
end | ||
|
||
private | ||
def find_first_name | ||
@first_name = | ||
if @split_name.length == 1 | ||
@full_name | ||
elsif @split_name.length == 2 | ||
@split_name[0] | ||
else | ||
@split_name.slice(0, (@split_name.length / 2)).join(' ') #integer division, so will always round to lower whole | ||
end | ||
end | ||
|
||
def find_last_name | ||
@last_name = | ||
if @split_name.length == 1 | ||
'' | ||
elsif @split_name.length == 2 | ||
@split_name[1] | ||
else | ||
@split_name.slice((@split_name.length/ 2), @split_name.length).join(' ') #integer division, so will always round to lower whole | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'rails_helper' | ||
|
||
describe Member do | ||
let(:first_name) { 'Emilio' } | ||
let(:last_name) { 'Estevez' } | ||
let(:full_name) { "#{first_name} #{last_name}" } | ||
let(:unicode_first) { 'Éöíñ'} | ||
let(:unicode_last) { 'Ńūñèž' } | ||
let(:unicode_full) { "#{unicode_first} #{unicode_last}" } | ||
let(:chinese_first) { '台'} | ||
let(:chinese_last) { '北' } | ||
let(:chinese_full) { "#{chinese_first} #{chinese_last}"} | ||
|
||
it 'correctly joins first and last name' do | ||
member = Member.new | ||
member.first_name = first_name | ||
member.last_name = last_name | ||
expect(member.name).to eq(full_name) | ||
end | ||
|
||
it 'correctly splits full_name into first and last name' do | ||
member = Member.new | ||
member.name = full_name | ||
member.save | ||
new_member = Member.find(member.id) | ||
expect(new_member.first_name).to eq(first_name) | ||
expect(new_member.last_name).to eq(last_name) | ||
expect(new_member.name).to eq(full_name) | ||
end | ||
|
||
it 'correctly handles unicode characters' do | ||
member = Member.new | ||
member.name = unicode_full | ||
member.save | ||
new_member = Member.find(member.id) | ||
expect(new_member.first_name).to eq(unicode_first) | ||
expect(new_member.last_name).to eq(unicode_last) | ||
expect(new_member.name).to eq(unicode_full) | ||
end | ||
|
||
it 'correctly handles high-value unicode characters' do | ||
member = Member.new | ||
member.name = chinese_full | ||
member.save | ||
new_member = Member.find(member.id) | ||
expect(new_member.first_name).to eq(chinese_first) | ||
expect(new_member.last_name).to eq(chinese_last) | ||
expect(new_member.name).to eq(chinese_full) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'spec_helper' | ||
|
||
describe NameSplitter do | ||
it 'splits names in two if there are only two elements' do | ||
first_name = 'Eric' | ||
last_name = 'Boersma' | ||
splitter = NameSplitter.new(full_name: "#{first_name} #{last_name}") | ||
expect(splitter.first_name).to eq(first_name) | ||
expect(splitter.last_name).to eq(last_name) | ||
end | ||
|
||
it 'splits the names in half if there are an even number of names given' do | ||
first_name = 'John Jacob' | ||
last_name = 'Jingleheimer Schmidt' | ||
splitter = NameSplitter.new(full_name: "#{first_name} #{last_name}") | ||
expect(splitter.first_name).to eq(first_name) | ||
expect(splitter.last_name).to eq(last_name) | ||
end | ||
|
||
it 'correctly handles single name full names' do | ||
first_name = 'Cher' | ||
last_name = '' | ||
splitter = NameSplitter.new(full_name: "#{first_name}") | ||
expect(splitter.first_name).to eq(first_name) | ||
expect(splitter.last_name).to eq(last_name) | ||
end | ||
|
||
it 'correctly handles names with three provided names' do | ||
first_name = 'Jennifer' | ||
last_name = 'Jason Leigh' | ||
splitter = NameSplitter.new(full_name: "#{first_name} #{last_name}") | ||
expect(splitter.first_name).to eq(first_name) | ||
expect(splitter.last_name).to eq(last_name) | ||
end | ||
|
||
it 'correctly handles names with five provided names' do | ||
first_name = 'Charles Philip' | ||
last_name = 'Arthur George Mountbatten-Windsor' | ||
splitter = NameSplitter.new(full_name: "#{first_name} #{last_name}") | ||
expect(splitter.first_name).to eq(first_name) | ||
expect(splitter.last_name).to eq(last_name) | ||
end | ||
|
||
it 'correctly handles names with six provided names' do | ||
first_name = 'Seal Henry Olusegun' | ||
last_name = 'Olumide Adeola Samuel' | ||
splitter = NameSplitter.new(full_name: "#{first_name} #{last_name}") | ||
expect(splitter.first_name).to eq(first_name) | ||
expect(splitter.last_name).to eq(last_name) | ||
end | ||
|
||
it 'does not group common name prefixes' do | ||
# This is an explicit recognition of a place where this class doesn't effectively handle an edge case of | ||
# a name which doesn't follow conventional Anglo naming standards. Hopefully, some day this test can be deleted, | ||
# but for now it stands as a recognition that the proper treatment of these names is not included in the | ||
# expected functionality of this class at this time. | ||
first_name = 'Josefina de los Sagrados' | ||
last_name = 'Corazones Fernández del Solar' | ||
splitter = NameSplitter.new(full_name: "#{first_name} #{last_name}") | ||
expect(splitter.first_name).to eq(first_name) | ||
expect(splitter.last_name).to eq(last_name) | ||
end | ||
end |