namae 0.2.1 → 0.3.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.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- Namae
2
- =====
1
+ Namae (名前)
2
+ ==========
3
3
  Namae is a parser for human names. It recognizes personal names of various
4
4
  cultural backgrounds and tries to split them into their component parts
5
5
  (e.g., given and family names, honorifics etc.).
@@ -53,13 +53,13 @@ Rails model:
53
53
  class Person < ActiveRecord::Base
54
54
  attr_accessible :name
55
55
 
56
- delegate :family, :initials, :to => :namae
56
+ delegate :family, :initials, :to => :namae
57
57
 
58
58
  private
59
59
 
60
- def namae
61
- @namae ||= Namae::Name.parse(name)
62
- end
60
+ def namae
61
+ @namae ||= Namae::Name.parse(name)
62
+ end
63
63
  end
64
64
 
65
65
  In this minimal example, we are using the method `Namae::Name.parse` which
data/Rakefile CHANGED
@@ -26,12 +26,12 @@ begin
26
26
  gem.license = 'AGPL'
27
27
 
28
28
  gem.summary =
29
- 'Namae parses personal names and splits them into their component parts.'
29
+ 'Namae (名前) parses personal names and splits them into their component parts.'
30
30
 
31
31
  gem.description = %q{
32
- Namae is a parser for human names. It recognizes personal names of various
33
- cultural backgrounds and tries to split them into their component parts
34
- (e.g., given and family names, honorifics etc.).
32
+ Namae (名前) is a parser for human names. It recognizes personal names of
33
+ various cultural backgrounds and tries to split them into their component
34
+ parts (e.g., given and family names, honorifics etc.).
35
35
  }.gsub(/\s+/, ' ')
36
36
 
37
37
  end
data/lib/namae/name.rb CHANGED
@@ -52,8 +52,17 @@ module Namae
52
52
  super(*attributes.values_at(*Name.parts))
53
53
  end
54
54
 
55
+ # @return [String] the name in sort order
56
+ def sort_order(delimiter = ', ')
57
+ [family_part, given_part].reject(&:empty?).join(delimiter)
58
+ end
59
+
60
+ # @return [String] the name in display order
61
+ def display_order
62
+ [given_part, family_part].reject(&:empty?).join(' ')
63
+ end
55
64
 
56
- # True if all the name components are nil.
65
+ # @return [Boolean] whether or not all the name components are nil.
57
66
  def empty?
58
67
  values.compact.empty?
59
68
  end
@@ -107,11 +116,12 @@ module Namae
107
116
  end
108
117
 
109
118
 
110
- # Describe the contents of this name in a string.
119
+ # @return [String] a string representation of the name
111
120
  def inspect
112
121
  "#<Name #{each_pair.map { |k,v| [k,v.inspect].join('=') if v }.compact.join(' ')}>"
113
122
  end
114
123
 
124
+ alias to_s display_order
115
125
 
116
126
  private
117
127
 
data/lib/namae/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Namae
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 2
5
- PATCH = 1
4
+ MINOR = 3
5
+ PATCH = 0
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.').freeze
data/namae.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "namae"
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sylvester Keil", "Dan Collis-Puro"]
12
- s.date = "2012-06-24"
13
- s.description = " Namae 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.). "
12
+ s.date = "2012-08-09"
13
+ 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.). "
14
14
  s.email = ["sylvester@keil.or.at", "dan@collispuro.com"]
15
15
  s.extra_rdoc_files = [
16
16
  "README.md"
@@ -48,7 +48,7 @@ Gem::Specification.new do |s|
48
48
  s.licenses = ["AGPL"]
49
49
  s.require_paths = ["lib"]
50
50
  s.rubygems_version = "1.8.10"
51
- s.summary = "Namae parses personal names and splits them into their component parts."
51
+ s.summary = "Namae (\u{540d}\u{524d}) parses personal names and splits them into their component parts."
52
52
 
53
53
  if s.respond_to? :specification_version then
54
54
  s.specification_version = 3
@@ -1,12 +1,12 @@
1
1
  module Namae
2
2
  describe 'Name' do
3
-
3
+
4
4
  describe '.new' do
5
-
5
+
6
6
  it 'returns an empty name by default' do
7
7
  Name.new.should be_empty
8
8
  end
9
-
9
+
10
10
  it 'sets all passed-in attributes' do
11
11
  Name.new(:given => 'Foo').given.should == 'Foo'
12
12
  end
@@ -14,20 +14,20 @@ module Namae
14
14
  it 'ignores unknown attributes' do
15
15
  Name.new(:foo => 'bar').should 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
22
  Name.parse('').should be_empty
23
23
  Name.parse('').should 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
27
  Name.parse('Plato and Sokrates').given.should == '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
33
  Name.new(:family => 'foo').values_at(:family).should == ['foo']
@@ -37,7 +37,7 @@ module Namae
37
37
  Name.new(:family => 'foo').values_at(:family).should == ['foo']
38
38
  end
39
39
  end
40
-
40
+
41
41
  describe '#initials' do
42
42
  it "returns the name's initials" do
43
43
  Name.new(:family => 'Poe', :given => 'Edgar A.').initials.should == 'E.A.P.'
@@ -47,7 +47,7 @@ module Namae
47
47
  Name.new(:family => 'Poe', :given => 'Edgar A.').initials(:expand => true).should == 'E.A. Poe'
48
48
  end
49
49
  end
50
-
50
+
51
51
  describe '#merge' do
52
52
  it 'merges the attributes in the given hash into the name' do
53
53
  Name.new.merge(:family => 'foo').family.should == 'foo'
@@ -56,21 +56,57 @@ module Namae
56
56
  it 'merges the attributes in the given name into the name' do
57
57
  Name.new.merge(Name.new(:family => 'foo')).family.should == 'foo'
58
58
  end
59
-
59
+
60
60
  it 'ignores unknown attributes' do
61
61
  Name.new.merge(:foo => 'bar').should be_empty
62
62
  end
63
-
63
+
64
64
  it 'ignores nil values' do
65
65
  Name.new(:family => 'foo').merge(:family => nil).family.should == 'foo'
66
66
  end
67
67
  end
68
-
68
+
69
69
  describe '#inspect' do
70
70
  it 'returns the name as a string' do
71
71
  Name.new(:given => 'Ichiro').inspect.should == '#<Name given="Ichiro">'
72
72
  end
73
73
  end
74
-
74
+
75
+ describe '#sort_order' do
76
+ it 'returns an empty string by default' do
77
+ Name.new.sort_order.should == ''
78
+ end
79
+
80
+ it 'returns the name in sort order' do
81
+ Name.new(:given => 'Ichiro', :family => 'Suzuki').sort_order.should == 'Suzuki, Ichiro'
82
+ end
83
+
84
+ it 'returns only the given if there is no family name' do
85
+ Name.new(:given => 'Ichiro').sort_order.should == 'Ichiro'
86
+ end
87
+
88
+ it 'returns only the family if there is no given name' do
89
+ Name.new(:family => 'Suzuki').sort_order.should == 'Suzuki'
90
+ end
91
+ end
92
+
93
+ describe '#display_order' do
94
+ it 'returns an empty string by default' do
95
+ Name.new.display_order.should == ''
96
+ end
97
+
98
+ it 'returns the name in display order' do
99
+ Name.new(:given => 'Ichiro', :family => 'Suzuki').display_order.should == 'Ichiro Suzuki'
100
+ end
101
+
102
+ it 'returns only the given if there is no family name' do
103
+ Name.new(:given => 'Ichiro').display_order.should == 'Ichiro'
104
+ end
105
+
106
+ it 'returns only the family if there is no given name' do
107
+ Name.new(:family => 'Suzuki').display_order.should == 'Suzuki'
108
+ end
109
+ end
110
+
75
111
  end
76
112
  end
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.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-24 00:00:00.000000000 Z
13
+ date: 2012-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: racc
17
- requirement: &70303877856980 !ruby/object:Gem::Requirement
17
+ requirement: &70302785391320 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.4.8
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *70303877856980
25
+ version_requirements: *70302785391320
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rdoc
28
- requirement: &70303877872020 !ruby/object:Gem::Requirement
28
+ requirement: &70302785414780 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '3.12'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70303877872020
36
+ version_requirements: *70302785414780
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &70303877871300 !ruby/object:Gem::Requirement
39
+ requirement: &70302785413280 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '1.1'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70303877871300
47
+ version_requirements: *70302785413280
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: simplecov
50
- requirement: &70303877870540 !ruby/object:Gem::Requirement
50
+ requirement: &70302785412480 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70303877870540
58
+ version_requirements: *70302785412480
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: ZenTest
61
- requirement: &70303877869820 !ruby/object:Gem::Requirement
61
+ requirement: &70302785410780 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 4.8.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70303877869820
69
+ version_requirements: *70302785410780
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: jeweler
72
- requirement: &70303877869300 !ruby/object:Gem::Requirement
72
+ requirement: &70302785408660 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,9 +77,9 @@ dependencies:
77
77
  version: 1.8.3
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70303877869300
81
- description: ! ' Namae is a parser for human names. It recognizes personal names of
82
- various cultural backgrounds and tries to split them into their component parts
80
+ version_requirements: *70302785408660
81
+ description: ! ' Namae (名前) is a parser for human names. It recognizes personal names
82
+ of various cultural backgrounds and tries to split them into their component parts
83
83
  (e.g., given and family names, honorifics etc.). '
84
84
  email:
85
85
  - sylvester@keil.or.at
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: 212543173299856896
134
+ hash: 1701548579686909699
135
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  none: false
137
137
  requirements:
@@ -143,5 +143,5 @@ rubyforge_project:
143
143
  rubygems_version: 1.8.10
144
144
  signing_key:
145
145
  specification_version: 3
146
- summary: Namae parses personal names and splits them into their component parts.
146
+ summary: Namae (名前) parses personal names and splits them into their component parts.
147
147
  test_files: []