namae 0.8.7 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4340f8745ce9d99b766c7b97f5b622b5ae8c9e2f
4
- data.tar.gz: ce330d12fa284b820121735722bfd24f31837cff
3
+ metadata.gz: ca79f39aed91f0816566c4374e8a80c2b10d7aef
4
+ data.tar.gz: 7e8b909610dab34673e3506f9abfbcbdba7f233a
5
5
  SHA512:
6
- metadata.gz: 1572cf9924176829e68b70ed94a485528ce13808e571cdfb3e2f77ad962a204d5d27520c3975c8012cdd0d93702fd0ec3a26ed10f09a4651ec079f2d2e756c1d
7
- data.tar.gz: 8cd73bc608b791c66b2504d1b4a598d4742d0ba1fb9e67b6e11e9bfafb32f35b0776b6e2e6bd9ba81a655327ee3489e47e8b6b5cc025a56f5c20d54ff063ecb4
6
+ metadata.gz: 1635916f55db9770ebc2b02b25af4b1d306119e5349db2ed6b5a146ab117e222081f7338c4e06a908fc1f1e8f58d887a99290cb4fecc7185f4baf3d508b15620
7
+ data.tar.gz: 891f0c209b26d0b0aabb79ad0cc1daa85410a900237482a36f0283ee674d603d68be12088ea9c4ae85ce35d1eee02ebb3dbe9b646d8052bd10e1c0e6b59246a8
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
- gem 'rspec', '~>2.14'
4
+ gem 'rspec', '~>3.0'
5
5
  gem 'rake', '~>10.1'
6
6
  gem 'cucumber', '~>1.3'
7
7
  end
@@ -13,24 +13,28 @@ end
13
13
 
14
14
  Then /^the BibTeX parts should be:$/ do |table|
15
15
  table.hashes.each do |row|
16
- @name.values_at(:given, :particle, :family, :suffix).map(&:to_s).should ==
17
- row.values_at('first', 'von', 'last', 'jr')
16
+ expect(
17
+ @name.values_at(:given, :particle, :family, :suffix).map(&:to_s)
18
+ ).to eq(row.values_at('first', 'von', 'last', 'jr'))
18
19
  end
19
20
  end
20
21
 
21
22
  Then /^the parts should be:$/ do |table|
22
23
  table.hashes.each do |row|
23
- @name.values_at(:given, :particle, :family, :suffix, :title, :appellation, :nick).map(&:to_s).should ==
24
- row.values_at('given', 'particle', 'family', 'suffix', 'title', 'appellation', 'nick')
24
+ expect(
25
+ @name.values_at(:given, :particle, :family, :suffix, :title, :appellation, :nick).map(&:to_s)
26
+ ).to eq(row.values_at('given', 'particle', 'family', 'suffix', 'title', 'appellation', 'nick'))
25
27
  end
26
28
  end
27
29
 
28
30
  Then /^there should be (\d+) names$/ do |count|
29
- @names.length.should == count.to_i
31
+ expect(@names.length).to eq(count.to_i)
30
32
  end
31
33
 
32
34
  Then /^the names should be:$/ do |table|
33
35
  table.hashes.each_with_index do |row, i|
34
- @names[i].values_at(*row.keys.map(&:to_sym)).map(&:to_s).should == row.values
36
+ expect(
37
+ @names[i].values_at(*row.keys.map(&:to_sym)).map(&:to_s)
38
+ ).to eq(row.values)
35
39
  end
36
- end
40
+ end
@@ -49,6 +49,27 @@ module Namae
49
49
  i.gsub!(/\s+/, '') unless options[:spaces]
50
50
  i
51
51
  end
52
+
53
+ # @param name [String] a name or part of a name
54
+ # @return [String] the passed-in name with normalized initials
55
+ def existing_initials_of(name, options = {})
56
+ return unless name
57
+
58
+ i = name.dup
59
+
60
+ i.gsub!(/\.+/, '')
61
+ i.gsub!(/\b[[:upper:]]+\b/) { |m| m.chars.join(' ') }
62
+
63
+ if options[:dots]
64
+ i.gsub!(/\b([[:upper:]])\b/, '\1.')
65
+ end
66
+
67
+ if !options[:spaces]
68
+ i.gsub!(/\b([[:upper:]]\.?)\s+/, '\1')
69
+ end
70
+
71
+ i
72
+ end
52
73
  end
53
74
 
54
75
  # A Name represents a single personal name, exposing its constituent
@@ -154,6 +175,13 @@ module Namae
154
175
  super(*arguments.flatten.map { |k| k.is_a?(Symbol) ? Name.parts.index(k) : k })
155
176
  end
156
177
 
178
+ def normalize_initials(options = {})
179
+ return self if given.nil?
180
+
181
+ options = Name.defaults[:initials].merge(options)
182
+ self.given = existing_initials_of given, options
183
+ self
184
+ end
157
185
 
158
186
  # @return [String] a string representation of the name
159
187
  def inspect
@@ -1,8 +1,8 @@
1
1
  module Namae
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 8
5
- PATCH = 7
4
+ MINOR = 9
5
+ PATCH = 0
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.').freeze
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: namae 0.8.7 ruby lib
5
+ # stub: namae 0.9.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "namae"
9
- s.version = "0.8.7"
9
+ s.version = "0.9.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Sylvester Keil", "Dan Collis-Puro"]
14
- s.date = "2014-05-14"
14
+ s.date = "2014-06-10"
15
15
  s.description = " Namae (\u{540d}\u{524d}) is a parser for human names. It recognizes personal names of various cultural backgrounds and tries to split them into their component parts (e.g., given and family names, honorifics etc.). "
16
16
  s.email = ["sylvester@keil.or.at", "dan@collispuro.com"]
17
17
  s.extra_rdoc_files = [
@@ -4,117 +4,128 @@ module Namae
4
4
  describe '.new' do
5
5
 
6
6
  it 'returns an empty name by default' do
7
- Name.new.should be_empty
7
+ expect(Name.new).to be_empty
8
8
  end
9
9
 
10
10
  it 'sets all passed-in attributes' do
11
- Name.new(:given => 'Foo').given.should == 'Foo'
11
+ expect(Name.new(:given => 'Foo').given).to eq('Foo')
12
12
  end
13
13
 
14
14
  it 'ignores unknown attributes' do
15
- Name.new(:foo => 'bar').should be_empty
15
+ expect(Name.new(:foo => 'bar')).to be_empty
16
16
  end
17
17
 
18
18
  end
19
19
 
20
20
  describe '.parse' do
21
21
  it 'returns an empty name for an empty string' do
22
- Name.parse('').should be_empty
23
- Name.parse('').should be_a(Name)
22
+ expect(Name.parse('')).to be_empty
23
+ expect(Name.parse('')).to be_a(Name)
24
24
  end
25
25
 
26
26
  it 'returns a single name object if there is more than one name' do
27
- Name.parse('Plato and Sokrates').given.should == 'Plato'
27
+ expect(Name.parse('Plato and Sokrates').given).to eq('Plato')
28
28
  end
29
29
  end
30
30
 
31
31
  describe '#values_at' do
32
32
  it 'returns an array with the given values' do
33
- Name.new(:family => 'foo').values_at(:family).should == ['foo']
33
+ expect(Name.new(:family => 'foo').values_at(:family)).to eq(['foo'])
34
34
  end
35
35
 
36
36
  it 'returns an array with the given values' do
37
- Name.new(:family => 'foo').values_at(:family).should == ['foo']
37
+ expect(Name.new(:family => 'foo').values_at(:family)).to eq(['foo'])
38
38
  end
39
39
  end
40
40
 
41
41
  describe '#initials' do
42
42
  it "returns the name's initials" do
43
- Name.new(:family => 'Poe', :given => 'Edgar A.').initials.should == 'E.A.P.'
43
+ expect(Name.new(:family => 'Poe', :given => 'Edgar A.').initials).to eq('E.A.P.')
44
44
  end
45
45
 
46
46
  it "returns the name's initials but leaves the family name expanded" do
47
- Name.new(:family => 'Poe', :given => 'Edgar A.').initials(:expand => true).should == 'E.A. Poe'
47
+ expect(Name.new(:family => 'Poe', :given => 'Edgar A.').initials(:expand => true)).to eq('E.A. Poe')
48
+ end
49
+ end
50
+
51
+ describe '#normalize_initials' do
52
+ it "adds dots to existing initials" do
53
+ expect(Name.new(:given => 'Edgar A').normalize_initials.given).to eq('Edgar A.')
54
+ expect(Name.new(:given => 'A').normalize_initials.given).to eq('A.')
55
+ expect(Name.new(:given => 'E A').normalize_initials.given).to eq('E.A.')
56
+ expect(Name.new(:given => 'EA').normalize_initials.given).to eq('E.A.')
57
+ expect(Name.new(:given => 'JFK').normalize_initials.given).to eq('J.F.K.')
58
+ expect(Name.new(:given => 'E-A').normalize_initials.given).to eq('E.-A.')
48
59
  end
49
60
  end
50
61
 
51
62
  describe '#merge' do
52
63
  it 'merges the attributes in the given hash into the name' do
53
- Name.new.merge(:family => 'foo').family.should == 'foo'
64
+ expect(Name.new.merge(:family => 'foo').family).to eq('foo')
54
65
  end
55
66
 
56
67
  it 'merges the attributes in the given name into the name' do
57
- Name.new.merge(Name.new(:family => 'foo')).family.should == 'foo'
68
+ expect(Name.new.merge(Name.new(:family => 'foo')).family).to eq('foo')
58
69
  end
59
70
 
60
71
  it 'ignores unknown attributes' do
61
- Name.new.merge(:foo => 'bar').should be_empty
72
+ expect(Name.new.merge(:foo => 'bar')).to be_empty
62
73
  end
63
74
 
64
75
  it 'ignores nil values' do
65
- Name.new(:family => 'foo').merge(:family => nil).family.should == 'foo'
76
+ expect(Name.new(:family => 'foo').merge(:family => nil).family).to eq('foo')
66
77
  end
67
78
  end
68
79
 
69
80
  describe '#inspect' do
70
81
  it 'returns the name as a string' do
71
- Name.new(:given => 'Ichiro').inspect.should == '#<Name given="Ichiro">'
82
+ expect(Name.new(:given => 'Ichiro').inspect).to eq('#<Name given="Ichiro">')
72
83
  end
73
84
  end
74
85
 
75
86
  describe '#sort_order' do
76
87
  it 'returns an empty string by default' do
77
- Name.new.sort_order.should == ''
88
+ expect(Name.new.sort_order).to eq('')
78
89
  end
79
90
 
80
91
  it 'returns the name in sort order' do
81
- Name.new(:given => 'Ichiro', :family => 'Suzuki').sort_order.should == 'Suzuki, Ichiro'
92
+ expect(Name.new(:given => 'Ichiro', :family => 'Suzuki').sort_order).to eq('Suzuki, Ichiro')
82
93
  end
83
94
 
84
95
  it 'returns only the given if there is no family name' do
85
- Name.new(:given => 'Ichiro').sort_order.should == 'Ichiro'
96
+ expect(Name.new(:given => 'Ichiro').sort_order).to eq('Ichiro')
86
97
  end
87
98
 
88
99
  it 'returns only the family if there is no given name' do
89
- Name.new(:family => 'Suzuki').sort_order.should == 'Suzuki'
100
+ expect(Name.new(:family => 'Suzuki').sort_order).to eq('Suzuki')
90
101
  end
91
102
 
92
103
  it 'includes the suffix' do
93
- Name.new(:family => 'Griffey', :suffix => 'Jr.').sort_order.should == 'Griffey, Jr.'
94
- Name.new(:family => 'Griffey', :given => 'Ken', :suffix => 'Jr.').sort_order.should == 'Griffey, Jr., Ken'
104
+ expect(Name.new(:family => 'Griffey', :suffix => 'Jr.').sort_order).to eq('Griffey, Jr.')
105
+ expect(Name.new(:family => 'Griffey', :given => 'Ken', :suffix => 'Jr.').sort_order).to eq('Griffey, Jr., Ken')
95
106
  end
96
107
  end
97
108
 
98
109
  describe '#display_order' do
99
110
  it 'returns an empty string by default' do
100
- Name.new.display_order.should == ''
111
+ expect(Name.new.display_order).to eq('')
101
112
  end
102
113
 
103
114
  it 'returns the name in display order' do
104
- Name.new(:given => 'Ichiro', :family => 'Suzuki').display_order.should == 'Ichiro Suzuki'
115
+ expect(Name.new(:given => 'Ichiro', :family => 'Suzuki').display_order).to eq('Ichiro Suzuki')
105
116
  end
106
117
 
107
118
  it 'returns only the given if there is no family name' do
108
- Name.new(:given => 'Ichiro').display_order.should == 'Ichiro'
119
+ expect(Name.new(:given => 'Ichiro').display_order).to eq('Ichiro')
109
120
  end
110
121
 
111
122
  it 'returns only the family if there is no given name' do
112
- Name.new(:family => 'Suzuki').display_order.should == 'Suzuki'
123
+ expect(Name.new(:family => 'Suzuki').display_order).to eq('Suzuki')
113
124
  end
114
125
 
115
126
  it 'includes the suffix' do
116
- Name.new(:family => 'Griffey', :suffix => 'Jr.').display_order.should == 'Griffey Jr.'
117
- Name.new(:family => 'Griffey', :given => 'Ken', :suffix => 'Jr.').display_order.should == 'Ken Griffey Jr.'
127
+ expect(Name.new(:family => 'Griffey', :suffix => 'Jr.').display_order).to eq('Griffey Jr.')
128
+ expect(Name.new(:family => 'Griffey', :given => 'Ken', :suffix => 'Jr.').display_order).to eq('Ken Griffey Jr.')
118
129
  end
119
130
  end
120
131
 
@@ -2,14 +2,14 @@ module Namae
2
2
  describe 'Parser' do
3
3
 
4
4
  it 'does not respond to .new' do
5
- Parser.should_not respond_to(:new)
5
+ expect(Parser).not_to respond_to(:new)
6
6
  end
7
7
 
8
8
  describe '.instance' do
9
9
  let(:parser) { Parser.instance }
10
10
 
11
11
  it 'returns the parser' do
12
- parser.should be_a(Parser)
12
+ expect(parser).to be_a(Parser)
13
13
  end
14
14
 
15
15
  describe '#next_token' do
@@ -19,35 +19,35 @@ module Namae
19
19
 
20
20
  describe 'when the input is empty' do
21
21
  it 'returns nil' do
22
- parser.send(:next_token).should be_nil
22
+ expect(parser.send(:next_token)).to be_nil
23
23
  end
24
24
  end
25
25
 
26
26
  describe 'when the next input is " and "' do
27
27
  before { parser.send(:input).string = ' and ' }
28
28
  it 'returns an AND token' do
29
- parser.send(:next_token).should == [:AND, :AND]
29
+ expect(parser.send(:next_token)).to eq([:AND, :AND])
30
30
  end
31
31
  end
32
32
 
33
33
  describe 'when the next input is " & "' do
34
34
  before { parser.send(:input).string = ' & ' }
35
35
  it 'returns an AND token' do
36
- parser.send(:next_token).should == [:AND, :AND]
36
+ expect(parser.send(:next_token)).to eq([:AND, :AND])
37
37
  end
38
38
  end
39
39
 
40
40
  describe 'when the next input is " , "' do
41
41
  before { parser.send(:input).string = ' , ' }
42
42
  it 'returns a COMMA token' do
43
- parser.send(:next_token).should == [:COMMA, :COMMA]
43
+ expect(parser.send(:next_token)).to eq([:COMMA, :COMMA])
44
44
  end
45
45
  end
46
46
 
47
47
  describe 'when the next input is " \'foo bar\' "' do
48
48
  before { parser.send(:input).string = " 'foo bar' " }
49
49
  it 'returns a NICK token' do
50
- parser.send(:next_token).should == [:NICK, 'foo bar']
50
+ expect(parser.send(:next_token)).to eq([:NICK, 'foo bar'])
51
51
  end
52
52
  end
53
53
 
@@ -55,7 +55,7 @@ module Namae
55
55
  describe "the next token is #{appellation.inspect}" do
56
56
  before { parser.send(:input).string = appellation }
57
57
  it 'returns an APPELLATION token' do
58
- parser.send(:next_token).should == [:APPELLATION, appellation]
58
+ expect(parser.send(:next_token)).to eq([:APPELLATION, appellation])
59
59
  end
60
60
  end
61
61
  end
@@ -64,11 +64,11 @@ module Namae
64
64
  describe "the next token is #{suffix.inspect}" do
65
65
  before { parser.send(:input).string = suffix }
66
66
  it 'returns an SUFFIX token' do
67
- parser.send(:next_token).should == [:SUFFIX, suffix]
67
+ expect(parser.send(:next_token)).to eq([:SUFFIX, suffix])
68
68
  end
69
69
 
70
70
  it 'the input matches the suffix pattern' do
71
- parser.suffix.should match(suffix)
71
+ expect(parser.suffix).to match(suffix)
72
72
  end
73
73
  end
74
74
  end
@@ -77,52 +77,52 @@ module Namae
77
77
 
78
78
  describe '#parse!' do
79
79
  it 'returns an empty list by default' do
80
- parser.parse!('').should be_empty
80
+ expect(parser.parse!('')).to be_empty
81
81
  end
82
82
 
83
83
  it 'returns a list of names' do
84
- parser.parse!('foo')[0].should be_a(Name)
84
+ expect(parser.parse!('foo')[0]).to be_a(Name)
85
85
  end
86
86
 
87
87
  describe 'when parsing a single name' do
88
88
 
89
89
  it 'treats "Ichiro" as a given name' do
90
- parser.parse!('Ichiro')[0].given.should == 'Ichiro'
90
+ expect(parser.parse!('Ichiro')[0].given).to eq('Ichiro')
91
91
  end
92
92
 
93
93
  it 'treats "Lord Byron" as a title and family name' do
94
- parser.parse!('Lord Byron')[0].values_at(:family, :title).should == ['Byron', 'Lord']
94
+ expect(parser.parse!('Lord Byron')[0].values_at(:family, :title)).to eq(['Byron', 'Lord'])
95
95
  end
96
96
 
97
97
  it 'parses given and family part name in "Ichiro Suzuki"' do
98
- parser.parse!('Ichiro Suzuki')[0].values_at(:given, :family).should == %w{Ichiro Suzuki}
98
+ expect(parser.parse!('Ichiro Suzuki')[0].values_at(:given, :family)).to eq(%w{Ichiro Suzuki})
99
99
  end
100
100
 
101
101
  it 'parses given, nick and family part name in "Yukihiro \'Matz\' Matsumoto"' do
102
- parser.parse!("Yukihiro 'Matz' Matsumoto")[0].values_at(:given, :family, :nick).should == %w{Yukihiro Matsumoto Matz}
102
+ expect(parser.parse!("Yukihiro 'Matz' Matsumoto")[0].values_at(:given, :family, :nick)).to eq(%w{Yukihiro Matsumoto Matz})
103
103
  end
104
104
 
105
105
  it 'parses given, nick and family part name in \'Yukihiro "Matz" Matsumoto\'' do
106
- parser.parse!('Yukihiro "Matz" Matsumoto')[0].values_at(:given, :family, :nick).should == %w{Yukihiro Matsumoto Matz}
106
+ expect(parser.parse!('Yukihiro "Matz" Matsumoto')[0].values_at(:given, :family, :nick)).to eq(%w{Yukihiro Matsumoto Matz})
107
107
  end
108
108
 
109
109
  it 'parses given and family name in "Poe, Edgar A."' do
110
- parser.parse!('Poe, Edgar A.')[0].values_at(:given, :family).should == ['Edgar A.', 'Poe']
110
+ expect(parser.parse!('Poe, Edgar A.')[0].values_at(:given, :family)).to eq(['Edgar A.', 'Poe'])
111
111
  end
112
112
 
113
113
  %w{Mr. Mr Mrs. Ms Herr Frau Miss}.each do |appellation|
114
114
  it "recognizes #{appellation.inspect} as an appellation" do
115
- parser.parse!([appellation, 'Edgar A. Poe'].join(' '))[0].appellation.should == appellation
115
+ expect(parser.parse!([appellation, 'Edgar A. Poe'].join(' '))[0].appellation).to eq(appellation)
116
116
  end
117
117
  end
118
118
 
119
119
  it 'parses common Jr. as a suffix in sort order' do
120
- parser.parse!('Griffey, Jr., Ken')[0].values_at(:given, :family, :suffix).should == ['Ken', 'Griffey', 'Jr.']
121
- parser.parse!('Griffey, Ken, Jr.')[0].values_at(:given, :family, :suffix).should == ['Ken', 'Griffey', 'Jr.']
120
+ expect(parser.parse!('Griffey, Jr., Ken')[0].values_at(:given, :family, :suffix)).to eq(['Ken', 'Griffey', 'Jr.'])
121
+ expect(parser.parse!('Griffey, Ken, Jr.')[0].values_at(:given, :family, :suffix)).to eq(['Ken', 'Griffey', 'Jr.'])
122
122
  end
123
123
 
124
124
  it 'parses common Jr. as a suffix in display order' do
125
- parser.parse!('Ken Griffey Jr.')[0].values_at(:given, :family, :suffix).should == ['Ken', 'Griffey', 'Jr.']
125
+ expect(parser.parse!('Ken Griffey Jr.')[0].values_at(:given, :family, :suffix)).to eq(['Ken', 'Griffey', 'Jr.'])
126
126
  end
127
127
 
128
128
  end
@@ -2,19 +2,19 @@ describe 'Namae' do
2
2
 
3
3
  describe '.parse' do
4
4
  it 'returns an empty list by default' do
5
- Namae.parse('').should be_empty
5
+ expect(Namae.parse('')).to be_empty
6
6
  end
7
7
  end
8
8
 
9
9
  describe '.parse!' do
10
10
  it 'returns an empty list by default' do
11
- Namae.parse!('').should be_empty
11
+ expect(Namae.parse!('')).to be_empty
12
12
  end
13
13
  end
14
14
 
15
15
  describe '.options' do
16
16
  it 'returns the parse options' do
17
- Namae.options.should equal(Namae::Parser.instance.options)
17
+ expect(Namae.options).to equal(Namae::Parser.instance.options)
18
18
  end
19
19
  end
20
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-14 00:00:00.000000000 Z
12
+ date: 2014-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simplecov