icu_name 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/icu_name/name.rb CHANGED
@@ -136,7 +136,7 @@ module ICU
136
136
 
137
137
  # Clean up characters in any name keeping only letters (including accented), hyphens, and single quotes.
138
138
  def clean(name)
139
- name.gsub!(/`/, "'")
139
+ name.gsub!(/[`‘’′‛]/, "'")
140
140
  name.gsub!(/./) do |m|
141
141
  if m.ord < 256
142
142
  # Keep Latin1 accented letters.
@@ -270,8 +270,15 @@ module ICU
270
270
  alts.push k if v == true || v.match(target)
271
271
  end
272
272
  end
273
+ alts.concat(automatic_alts(names))
273
274
  alts
274
275
  end
276
+
277
+ # Add automatic alternatives - those not dependent on a compiled list.
278
+ # Currently only provides alternative for apostrophes, as backticks are often used instead by FIDE.
279
+ def automatic_alts(names)
280
+ names.find_all{|n| n.index("'")}.map{|n| n.gsub!("'", "`")}
281
+ end
275
282
 
276
283
  # Compile an alternative names hash (for either first names or last names) before matching is first attempted.
277
284
  def self.compile_alts(type, data=nil, force=false)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ICU
4
4
  class Name
5
- VERSION = "1.0.2"
5
+ VERSION = "1.0.3"
6
6
  end
7
7
  end
data/spec/name_spec.rb CHANGED
@@ -108,14 +108,28 @@ module ICU
108
108
  end
109
109
  end
110
110
 
111
- context "last names involving a quote" do
112
- it "should be handled correctly" do
111
+ context "last names involving single quote-like characters" do
112
+ before(:each) do
113
+ @una = Name.new('Una', "O'Boyle")
114
+ end
115
+
116
+ it "should use apostrophe (0027) as the canonical choice" do
113
117
  Name.new('una', "O'boyle").name.should == "Una O'Boyle"
118
+ Name.new('Una', "o’boyle").name.should == "Una O'Boyle"
114
119
  Name.new('jonathan', 'd`arcy').name.should == "Jonathan D'Arcy"
115
- Name.new('erwin e', "L'AMI").name.should == "Erwin E. L'Ami"
120
+ Name.new('erwin e', "LAMI").name.should == "Erwin E. L'Ami"
116
121
  Name.new('cormac', "o brien").name.should == "Cormac O'Brien"
117
122
  Name.new('türko', "o özgür").name.should == "Türko O'Özgür"
118
- Name.new('türko', "lzgür").name.should == "Türko L'Özgür"
123
+ Name.new('türko', "l‘özgür").name.should == "Türko L'Özgür"
124
+ end
125
+
126
+ it "backticks (0060), opening (2018) and closing (2019) single quotes, primes (2032) and high reversed 9 quotes (201B) should be equivalent" do
127
+ @una.match("Una", "O`Boyle").should be_true
128
+ @una.match("Una", "O’Boyle").should be_true
129
+ @una.match("Una", "O‘Boyle").should be_true
130
+ @una.match("Una", "O′Boyle").should be_true
131
+ @una.match("Una", "O‛Boyle").should be_true
132
+ @una.match("Una", "O‚Boyle").should be_false
119
133
  end
120
134
  end
121
135
 
@@ -471,9 +485,13 @@ module ICU
471
485
  Name.new('Sean', 'Bradley').alternatives(:first).should =~ []
472
486
  end
473
487
 
488
+ it "should have automatic last name alternatives for apostrophes to cater for FIDE's habits" do
489
+ Name.new('Mairead', "O'Siochru").alternatives(:last).should =~ ["O`Siochru"]
490
+ Name.new('Erwin E.', "L`Ami").alternatives(:last).should =~ ["L`Ami"]
491
+ end
492
+
474
493
  it "should not have any last name alternatives" do
475
494
  Name.new('William', 'Ffrench').alternatives(:last).should =~ []
476
- Name.new('Mairead', "O'Siochru").alternatives(:last).should =~ []
477
495
  Name.new('Oissine', 'Murphy').alternatives(:last).should =~ []
478
496
  Name.new('Debbie', 'Quinn').alternatives(:last).should =~ []
479
497
  end
@@ -495,7 +513,7 @@ module ICU
495
513
 
496
514
  it "should have some last name alternatives" do
497
515
  Name.new('William', 'Ffrench').alternatives(:last).should =~ %w{French}
498
- Name.new('Mairead', "O'Siochru").alternatives(:last).should =~ %w{King}
516
+ Name.new('Mairead', "O'Siochru").alternatives(:last).should =~ %w{King O`Siochru}
499
517
  Name.new('Oissine', 'Murphy').alternatives(:last).should =~ %w{Murchadha}
500
518
  Name.new('Debbie', 'Quinn').alternatives(:last).should =~ %w{Benjamin}
501
519
  Name.new('Mark', 'Quinn').alternatives(:last).should =~ []
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 2
9
- version: 1.0.2
8
+ - 3
9
+ version: 1.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Orr
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-17 00:00:00 +01:00
17
+ date: 2011-05-28 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency