diff --git a/lib/nameable/latin.rb b/lib/nameable/latin.rb index dc31382..5d6ca4d 100644 --- a/lib/nameable/latin.rb +++ b/lib/nameable/latin.rb @@ -120,7 +120,7 @@ def parse(name) raise InvalidNameError unless name if name.class == String if name.index(',') - name = "#{Regexp.last_match(2)} #{Regexp.last_match(1)}" if name =~ /^([a-z]+)\s*,\s*,*([^,]*)/i + name = "#{Regexp.last_match(2)} #{Regexp.last_match(1)}" if name =~ /^([a-z]+(?:\s*-{1,2}\s*[a-z]+)*)\s*,\s*,*([^,]*)/i end name = name.strip.split(/\s+/) diff --git a/spec/nameable/latin_spec.rb b/spec/nameable/latin_spec.rb index 04154b7..39f893f 100644 --- a/spec/nameable/latin_spec.rb +++ b/spec/nameable/latin_spec.rb @@ -151,9 +151,19 @@ end end + context 'with a hyphenated last name' do - ['Horn - Derp', 'Horn-Derp', 'Horn--Derp', 'Horn -- Derp'].each do |last| - it_behaves_like :generalized_parsing, "Chris #{last}", [nil, 'Chris', nil, 'Horn-Derp', nil] + hyphenated_last_names = ['Horn - Derp', 'Horn-Derp', 'Horn--Derp', 'Horn -- Derp'] + context 'in standard order' do + hyphenated_last_names.each do |last| + it_behaves_like :generalized_parsing, "Chris #{last}", [nil, 'Chris', nil, 'Horn-Derp', nil] + end + end + + context 'in last name, first name' do + hyphenated_last_names.each do |last| + it_behaves_like :generalized_parsing, "#{last}, Chris", [nil, 'Chris', nil, 'Horn-Derp', nil] + end end end end