Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for post nominal initials, as per original Perl library #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.byebug_history
Gemfile.lock
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Hoe.spec('namelib') do |p|
self.readme_file = 'README.md'
developer("Gaspard d'Hautefeuille.eu", "[email protected]")
license 'GPL'
extra_dev_deps << ['minitest', '~> 4.0']
extra_dev_deps << ['minitest', '~> 5.0']
end
35 changes: 34 additions & 1 deletion lib/namelib.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
require 'byebug'
module Namelib
VERSION = '2.1.0'

POST_NOMINAL_INITIALS = %w(
VC GC KG LG KT LT KP GCB OM GCSI GCMG GCIE GCVO GBE CH KCB DCB KCSI KCMG
DCMG KCIE KCVO DCVO KBE DBE CB CSI CMG CIE CVO CBE DSO LVO OBE ISO MVO MBE
IOM CGC RRC DSC MC DFC AFC ARRC OBI DCM CGM GM IDSM DSM MM DFM AFM SGM IOM
CPM QGM RVM BEM QPM QFSM QAM CPM MSM ERD VD TD UD ED RD VRD AE

PC ADC QHP QHS QHDS QHNS QHC SCJ J LJ QS SL QC KC JP DL MP MSP MSYP AM AM
MLA MEP DBEnv DConstMgt DREst EdD DPhil PhD DLitt DSocSci MD EngD DD LLD
DProf MA MArch MAnth MSc MMORSE MMath MMathStat MPharm MPhil MSc MSci MSt
MRes MEng MChem MBiochem MSocSc MMus LLM BCL MPhys MComp MAcc MFin MBA MPA
MEd MEP MEnt MCGI MGeol MLitt MEarthSc MClinRes BA BSc LLB BEng MBChB FdA
FdSc FdEng PgDip PgD PgCert PgC PgCLTHE AUH AKC AUS HNC HNCert HND HNDip
DipHE Dip OND CertHE ACSM MCSM DIC AICSM ARSM ARCS LLB LLM BCL MJur DPhil
PhD LLD DipLP FCILEx GCILEx ACILEx CQSW DipSW BSW MSW FCILT CMILT MILT CPL
CTP CML PLS CTL DLP PLog EJLog ESLog EMLog JrLog Log SrLog BArch MArch ARB
RIBA RIAS RIAI RSAW MB BM BS BCh BChir MRCS FRCS MS MCh. MRCP FRCP MRCPCH
FRCPCH MRCPath MFPM FFPM BDS MRCPsych FRCPsych MRCOG FRCOG MCEM FCEM FRCA
FFPMRCA MRCGP FRCGP BSc MScChiro MChiro MSc DC LFHOM MFHOM FFHOM FADO FBDO
FCOptom MCOptom MOst DPT MCSP FCSP. SROT MSCR FSCR. CPhT RN VN RVN BVSc
BVetMed VetMB BVM&S MRCVS FRCVS FAWM PGCAP PGCHE PGCE PGDE BEd NPQH QTS
CSci CSciTeach RSci RSciTech CEng IEng EngTech ICTTech DEM MM CMarEng
CMarSci CMarTech IMarEng MarEngTech RGN SRN RMN RSCN SEN EN RNMH RN RM RN1
RNA RN2 RN3 RNMH RN4 RN5 RNLD RN6 RN8 RNC RN7 RN9 RHV RSN ROH RFHN SPAN
SPMH SPCN SPLD SPHP SCHM SCLD SPCC SPDN V100 V200 V300 LPE MSc
)

# Returns a new +String+ with the contents properly namecased
def nc(options = {})
Namelib.nc self, options
Expand All @@ -16,7 +43,7 @@ def self.nc! str, options = {}
end

def self.nc str, options = {}
options = { :lazy => true, :irish => true, :spanish => true }.merge options
options = { :lazy => true, :irish => true, :spanish => true, :post_nominal_initials => true }.merge options

# Skip if string is mixed case
if options[:lazy]
Expand Down Expand Up @@ -80,6 +107,12 @@ def self.nc str, options = {}
end
end

if options[:post_nominal_initials]
POST_NOMINAL_INITIALS.each do |pni|
localstring.gsub!(/(\b)(#{pni})(.?\s*)$/i, '\1' + pni + '\3')
end
end

localstring
end
end
Expand Down
2 changes: 1 addition & 1 deletion namelib.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<rdoc>, ["~> 4.0"])
s.add_development_dependency(%q<minitest>, ["~> 4.0"])
s.add_development_dependency(%q<minitest>, ["~> 5.0"])
s.add_development_dependency(%q<hoe>, ["~> 3.13"])
else
s.add_dependency(%q<rdoc>, ["~> 4.0"])
Expand Down
17 changes: 17 additions & 0 deletions test/test_namelib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def setup
"Henry VIII", "Louis III", "Louis XIV",
"Charles II", "Fred XLIX", "Yusof bin Ishak",
]

@proper_names_with_post_initials = [
"Keith Smith PhD", "John McAfee MEarthSc",
"Jan van Yke, MCOptom", "John el Grecco, PhD.",
"Mike Spaceattheend RSciTech. ",
"Richard de l'Hôpital Mas i Gavarró V200"
]
end

def test_namelib
Expand All @@ -41,6 +48,16 @@ def test_namelib
end
end

def test_namelib_post_nominal_initials
@proper_names_with_post_initials.each do |name|
assert_equal(name, Namelib(name.downcase))
n = name.dup
n.extend(Namelib)
assert_equal(name, n.nc)
assert_equal(name, Namelib(name))
end
end

def test_namelib_modify
@proper_names.each do |name|
nc_name = Namelib!(name.downcase)
Expand Down