nomen 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/README.md +17 -5
- data/lib/nomen.rb +25 -1
- data/lib/nomen/formatters.rb +1 -1
- data/lib/nomen/formatters/full.rb +5 -5
- data/lib/nomen/formatters/inverted.rb +5 -5
- data/lib/nomen/version.rb +2 -2
- data/spec/formatters/full_spec.rb +71 -31
- data/spec/formatters/inverted_spec.rb +71 -31
- data/spec/nomen_spec.rb +54 -0
- metadata +6 -7
- data/lib/nomen/name.rb +0 -23
- data/spec/name_spec.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e25c9721ac53215d2b874c8ffb5a4e72807f884c
|
4
|
+
data.tar.gz: 46f496975c446826abe95f3774678cc550af3870
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0d3a1c1fef929642b188e8d77bc59fd879856d9b6c954de88aebb6c690493be5c53f98d292f82758743a6dd31c8d9cf528de28a6487b5ed4f993fa0669ea11
|
7
|
+
data.tar.gz: 04d9fd97b8b8c07fe7721ac49dad7e7b7a029aa679586bf7be57a346c93276098a240b1ce37242e21d84fe8bdf322229306cc87cd9d302bea3d49d8456e853ca
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,20 +1,31 @@
|
|
1
|
-
|
1
|
+
Nomen
|
2
|
+
========
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/nomen.png)][gem]
|
5
|
+
[![Build Status](https://secure.travis-ci.org/abevoelker/nomen.png?branch=master)][travis]
|
6
|
+
[![Dependency Status](https://gemnasium.com/abevoelker/nomen.png)][gemnasium]
|
7
|
+
|
8
|
+
[gem]: https://rubygems.org/gems/nomen
|
9
|
+
[travis]: http://travis-ci.org/abevoelker/nomen
|
10
|
+
[gemnasium]: https://gemnasium.com/abevoelker/nomen
|
2
11
|
|
3
12
|
Simple library for formatting (and maybe later, parsing) human names.
|
4
13
|
|
5
|
-
|
14
|
+
Description
|
15
|
+
-----------
|
6
16
|
|
7
17
|
The name is latin for "name"; no misandry intended. For now I'm only handling
|
8
18
|
my current use case, which is very basic formatting of American-style names.
|
9
19
|
|
10
20
|
I am aware of the [complexity of][patio11] human names.
|
11
21
|
|
12
|
-
|
22
|
+
Synopsis
|
23
|
+
--------
|
13
24
|
|
14
25
|
```ruby
|
15
26
|
require 'nomen'
|
16
27
|
|
17
|
-
n = Nomen
|
28
|
+
n = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
18
29
|
n.format # => "Katya Verenice Voelker M.D."
|
19
30
|
n.format(:inverted) # => "Voelker, Katya Verenice M.D."
|
20
31
|
n.middle = nil
|
@@ -22,7 +33,8 @@ n.format # => "Katya Voelker M.D."
|
|
22
33
|
n.format(:inverted) # => "Voelker, Katya M.D."
|
23
34
|
```
|
24
35
|
|
25
|
-
|
36
|
+
Copyright
|
37
|
+
---------
|
26
38
|
|
27
39
|
Copyright (c) 2013 Abe Voelker. Released under the terms of the MIT license.
|
28
40
|
See LICENSE for details.
|
data/lib/nomen.rb
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
class Nomen
|
2
|
+
FRAGMENTS = [:first, :middle, :last, :suffix]
|
3
|
+
attr_accessor *FRAGMENTS
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
name_opts = opts.select{|k,v| FRAGMENTS.include?(k)}
|
7
|
+
name_opts.each{|k,v| send("#{k}=".to_sym, v)}
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def format(type=:full)
|
12
|
+
Nomen::Formatters.lookup(type).format(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
FRAGMENTS.reduce({}){|a,f| a[f] = send(f); a}
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
FRAGMENTS.each{|m| return false if self.send(m) != other.send(m)}
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
1
26
|
require 'nomen/version'
|
2
|
-
require 'nomen/name'
|
3
27
|
require 'nomen/formatters'
|
data/lib/nomen/formatters.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
|
1
|
+
class Nomen
|
2
2
|
module Formatters
|
3
3
|
class Full
|
4
4
|
|
5
5
|
def self.format(name)
|
6
6
|
String.new.tap do |str|
|
7
|
-
if name.first
|
7
|
+
if name.first && !name.first.empty?
|
8
8
|
str << name.first
|
9
9
|
end
|
10
|
-
if name.middle
|
10
|
+
if name.middle && !name.middle.empty?
|
11
11
|
str << (str.empty? ? name.middle : " #{name.middle}")
|
12
12
|
end
|
13
|
-
if name.last
|
13
|
+
if name.last && !name.last.empty?
|
14
14
|
str << (str.empty? ? name.last : " #{name.last}")
|
15
15
|
end
|
16
|
-
if name.suffix
|
16
|
+
if name.suffix && !name.suffix.empty?
|
17
17
|
str << (str.empty? ? name.suffix : " #{name.suffix}")
|
18
18
|
end
|
19
19
|
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
|
1
|
+
class Nomen
|
2
2
|
module Formatters
|
3
3
|
class Inverted
|
4
4
|
|
5
5
|
def self.format(name)
|
6
6
|
String.new.tap do |str|
|
7
|
-
if name.last
|
7
|
+
if name.last && !name.last.empty?
|
8
8
|
if [name.first, name.middle, name.suffix].reject(&:nil?).reject(&:empty?).any?
|
9
9
|
str << "#{name.last},"
|
10
10
|
else
|
11
11
|
str << name.last
|
12
12
|
end
|
13
13
|
end
|
14
|
-
if name.first
|
14
|
+
if name.first && !name.first.empty?
|
15
15
|
str << (str.empty? ? name.first : " #{name.first}")
|
16
16
|
end
|
17
|
-
if name.middle
|
17
|
+
if name.middle && !name.middle.empty?
|
18
18
|
str << (str.empty? ? name.middle : " #{name.middle}")
|
19
19
|
end
|
20
|
-
if name.suffix
|
20
|
+
if name.suffix && !name.suffix.empty?
|
21
21
|
str << (str.empty? ? name.suffix : " #{name.suffix}")
|
22
22
|
end
|
23
23
|
end
|
data/lib/nomen/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0.
|
1
|
+
class Nomen
|
2
|
+
VERSION = "0.0.2"
|
3
3
|
end
|
@@ -3,156 +3,196 @@ require File.dirname(__FILE__) + '/formatters_helper'
|
|
3
3
|
describe Nomen::Formatters::Full do
|
4
4
|
context 'formatting a name' do
|
5
5
|
|
6
|
+
# transforms #<Nomen @first="Bob"> into #<Nomen @first="Bob", @middle=nil, @last=nil, suffix=nil>
|
7
|
+
def nils(nomen)
|
8
|
+
Nomen.new(nomen.to_h)
|
9
|
+
end
|
10
|
+
|
11
|
+
# transforms #<Nomen @first="Bob"> into #<Nomen @first="Bob", @middle="", @last="", suffix="">
|
12
|
+
def blanks(nomen)
|
13
|
+
Nomen.new(nomen.to_h.inject({}){|a,(k,v)| a[k] = (v.nil? ? '' : v); a })
|
14
|
+
end
|
15
|
+
|
6
16
|
# name segment combinations were generated with
|
7
|
-
#
|
17
|
+
# f = Nomen::FRAGMENTS; f.size.downto(1).map{|i| f.combination(i).to_a}.flatten(1)
|
8
18
|
|
9
19
|
context 'with [:first, :middle, :last, :suffix]' do
|
10
20
|
before do
|
11
|
-
@name = Nomen
|
21
|
+
@name = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
12
22
|
end
|
13
23
|
|
14
24
|
it 'should format correctly' do
|
15
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
25
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Verenice Voelker M.D.')
|
26
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
27
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
16
28
|
end
|
17
29
|
end
|
18
30
|
|
19
31
|
context 'with [:first, :middle, :last]' do
|
20
32
|
before do
|
21
|
-
@name = Nomen
|
33
|
+
@name = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker')
|
22
34
|
end
|
23
35
|
|
24
36
|
it 'should format correctly' do
|
25
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
37
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Verenice Voelker')
|
38
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
39
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
26
40
|
end
|
27
41
|
end
|
28
42
|
|
29
43
|
context 'with [:first, :middle, :suffix]' do
|
30
44
|
before do
|
31
|
-
@name = Nomen
|
45
|
+
@name = Nomen.new(first: 'Katya', middle: 'Verenice', suffix: 'M.D.')
|
32
46
|
end
|
33
47
|
|
34
48
|
it 'should format correctly' do
|
35
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
49
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Verenice M.D.')
|
50
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
51
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
36
52
|
end
|
37
53
|
end
|
38
54
|
|
39
55
|
context 'with [:first, :last, :suffix]' do
|
40
56
|
before do
|
41
|
-
@name = Nomen
|
57
|
+
@name = Nomen.new(first: 'Katya', last: 'Voelker', suffix: 'M.D.')
|
42
58
|
end
|
43
59
|
|
44
60
|
it 'should format correctly' do
|
45
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
61
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Voelker M.D.')
|
62
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
63
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
46
64
|
end
|
47
65
|
end
|
48
66
|
|
49
67
|
context 'with [:middle, :last, :suffix]' do
|
50
68
|
before do
|
51
|
-
@name = Nomen
|
69
|
+
@name = Nomen.new(middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
52
70
|
end
|
53
71
|
|
54
72
|
it 'should format correctly' do
|
55
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
73
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Verenice Voelker M.D.')
|
74
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
75
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
56
76
|
end
|
57
77
|
end
|
58
78
|
|
59
79
|
context 'with [:first, :middle]' do
|
60
80
|
before do
|
61
|
-
@name = Nomen
|
81
|
+
@name = Nomen.new(first: 'Katya', middle: 'Verenice')
|
62
82
|
end
|
63
83
|
|
64
84
|
it 'should format correctly' do
|
65
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
85
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Verenice')
|
86
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
87
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
66
88
|
end
|
67
89
|
end
|
68
90
|
|
69
91
|
context 'with [:first, :last]' do
|
70
92
|
before do
|
71
|
-
@name = Nomen
|
93
|
+
@name = Nomen.new(first: 'Katya', last: 'Voelker')
|
72
94
|
end
|
73
95
|
|
74
96
|
it 'should format correctly' do
|
75
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
97
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Voelker')
|
98
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
99
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
76
100
|
end
|
77
101
|
end
|
78
102
|
|
79
103
|
context 'with [:first, :suffix]' do
|
80
104
|
before do
|
81
|
-
@name = Nomen
|
105
|
+
@name = Nomen.new(first: 'Katya', suffix: 'M.D.')
|
82
106
|
end
|
83
107
|
|
84
108
|
it 'should format correctly' do
|
85
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
109
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya M.D.')
|
110
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
111
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
86
112
|
end
|
87
113
|
end
|
88
114
|
|
89
115
|
context 'with [:middle, :last]' do
|
90
116
|
before do
|
91
|
-
@name = Nomen
|
117
|
+
@name = Nomen.new(middle: 'Verenice', last: 'Voelker')
|
92
118
|
end
|
93
119
|
|
94
120
|
it 'should format correctly' do
|
95
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
121
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Verenice Voelker')
|
122
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
123
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
96
124
|
end
|
97
125
|
end
|
98
126
|
|
99
127
|
context 'with [:middle, :suffix]' do
|
100
128
|
before do
|
101
|
-
@name = Nomen
|
129
|
+
@name = Nomen.new(middle: 'Verenice', suffix: 'M.D.')
|
102
130
|
end
|
103
131
|
|
104
132
|
it 'should format correctly' do
|
105
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
133
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Verenice M.D.')
|
134
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
135
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
106
136
|
end
|
107
137
|
end
|
108
138
|
|
109
139
|
context 'with [:last, :suffix]' do
|
110
140
|
before do
|
111
|
-
@name = Nomen
|
141
|
+
@name = Nomen.new(last: 'Voelker', suffix: 'M.D.')
|
112
142
|
end
|
113
143
|
|
114
144
|
it 'should format correctly' do
|
115
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
145
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Voelker M.D.')
|
146
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
147
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
116
148
|
end
|
117
149
|
end
|
118
150
|
|
119
151
|
context 'with [:first]' do
|
120
152
|
before do
|
121
|
-
@name = Nomen
|
153
|
+
@name = Nomen.new(first: 'Katya')
|
122
154
|
end
|
123
155
|
|
124
156
|
it 'should format correctly' do
|
125
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
157
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya')
|
158
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
159
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
126
160
|
end
|
127
161
|
end
|
128
162
|
|
129
163
|
context 'with [:middle]' do
|
130
164
|
before do
|
131
|
-
@name = Nomen
|
165
|
+
@name = Nomen.new(middle: 'Verenice')
|
132
166
|
end
|
133
167
|
|
134
168
|
it 'should format correctly' do
|
135
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
169
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Verenice')
|
170
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
171
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
136
172
|
end
|
137
173
|
end
|
138
174
|
|
139
175
|
context 'with [:last]' do
|
140
176
|
before do
|
141
|
-
@name = Nomen
|
177
|
+
@name = Nomen.new(last: 'Voelker')
|
142
178
|
end
|
143
179
|
|
144
180
|
it 'should format correctly' do
|
145
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
181
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Voelker')
|
182
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
183
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
146
184
|
end
|
147
185
|
end
|
148
186
|
|
149
187
|
context 'with [:suffix]' do
|
150
188
|
before do
|
151
|
-
@name = Nomen
|
189
|
+
@name = Nomen.new(suffix: 'M.D.')
|
152
190
|
end
|
153
191
|
|
154
192
|
it 'should format correctly' do
|
155
|
-
expect(Nomen::Formatters::Full.format(@name)).to
|
193
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('M.D.')
|
194
|
+
expect(Nomen::Formatters::Full.format(nils(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
195
|
+
expect(Nomen::Formatters::Full.format(blanks(@name))).to eq(Nomen::Formatters::Full.format(@name))
|
156
196
|
end
|
157
197
|
end
|
158
198
|
end
|
@@ -3,156 +3,196 @@ require File.dirname(__FILE__) + '/formatters_helper'
|
|
3
3
|
describe Nomen::Formatters::Inverted do
|
4
4
|
context 'formatting a name' do
|
5
5
|
|
6
|
+
# transforms #<Nomen @first="Bob"> into #<Nomen @first="Bob", @middle=nil, @last=nil, suffix=nil>
|
7
|
+
def nils(nomen)
|
8
|
+
Nomen.new(nomen.to_h)
|
9
|
+
end
|
10
|
+
|
11
|
+
# transforms #<Nomen @first="Bob"> into #<Nomen @first="Bob", @middle="", @last="", suffix="">
|
12
|
+
def blanks(nomen)
|
13
|
+
Nomen.new(nomen.to_h.inject({}){|a,(k,v)| a[k] = (v.nil? ? '' : v); a })
|
14
|
+
end
|
15
|
+
|
6
16
|
# name segment combinations were generated with
|
7
|
-
#
|
17
|
+
# f = Nomen::FRAGMENTS; f.size.downto(1).map{|i| f.combination(i).to_a}.flatten(1)
|
8
18
|
|
9
19
|
context 'with [:first, :middle, :last, :suffix]' do
|
10
20
|
before do
|
11
|
-
@name = Nomen
|
21
|
+
@name = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
12
22
|
end
|
13
23
|
|
14
24
|
it 'should format correctly' do
|
15
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
25
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Katya Verenice M.D.')
|
26
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
27
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
16
28
|
end
|
17
29
|
end
|
18
30
|
|
19
31
|
context 'with [:first, :middle, :last]' do
|
20
32
|
before do
|
21
|
-
@name = Nomen
|
33
|
+
@name = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker')
|
22
34
|
end
|
23
35
|
|
24
36
|
it 'should format correctly' do
|
25
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
37
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Katya Verenice')
|
38
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
39
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
26
40
|
end
|
27
41
|
end
|
28
42
|
|
29
43
|
context 'with [:first, :middle, :suffix]' do
|
30
44
|
before do
|
31
|
-
@name = Nomen
|
45
|
+
@name = Nomen.new(first: 'Katya', middle: 'Verenice', suffix: 'M.D.')
|
32
46
|
end
|
33
47
|
|
34
48
|
it 'should format correctly' do
|
35
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
49
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Katya Verenice M.D.')
|
50
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
51
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
36
52
|
end
|
37
53
|
end
|
38
54
|
|
39
55
|
context 'with [:first, :last, :suffix]' do
|
40
56
|
before do
|
41
|
-
@name = Nomen
|
57
|
+
@name = Nomen.new(first: 'Katya', last: 'Voelker', suffix: 'M.D.')
|
42
58
|
end
|
43
59
|
|
44
60
|
it 'should format correctly' do
|
45
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
61
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Katya M.D.')
|
62
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
63
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
46
64
|
end
|
47
65
|
end
|
48
66
|
|
49
67
|
context 'with [:middle, :last, :suffix]' do
|
50
68
|
before do
|
51
|
-
@name = Nomen
|
69
|
+
@name = Nomen.new(middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
52
70
|
end
|
53
71
|
|
54
72
|
it 'should format correctly' do
|
55
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
73
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Verenice M.D.')
|
74
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
75
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
56
76
|
end
|
57
77
|
end
|
58
78
|
|
59
79
|
context 'with [:first, :middle]' do
|
60
80
|
before do
|
61
|
-
@name = Nomen
|
81
|
+
@name = Nomen.new(first: 'Katya', middle: 'Verenice')
|
62
82
|
end
|
63
83
|
|
64
84
|
it 'should format correctly' do
|
65
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
85
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Katya Verenice')
|
86
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
87
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
66
88
|
end
|
67
89
|
end
|
68
90
|
|
69
91
|
context 'with [:first, :last]' do
|
70
92
|
before do
|
71
|
-
@name = Nomen
|
93
|
+
@name = Nomen.new(first: 'Katya', last: 'Voelker')
|
72
94
|
end
|
73
95
|
|
74
96
|
it 'should format correctly' do
|
75
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
97
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Katya')
|
98
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
99
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
76
100
|
end
|
77
101
|
end
|
78
102
|
|
79
103
|
context 'with [:first, :suffix]' do
|
80
104
|
before do
|
81
|
-
@name = Nomen
|
105
|
+
@name = Nomen.new(first: 'Katya', suffix: 'M.D.')
|
82
106
|
end
|
83
107
|
|
84
108
|
it 'should format correctly' do
|
85
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
109
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Katya M.D.')
|
110
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
111
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
86
112
|
end
|
87
113
|
end
|
88
114
|
|
89
115
|
context 'with [:middle, :last]' do
|
90
116
|
before do
|
91
|
-
@name = Nomen
|
117
|
+
@name = Nomen.new(middle: 'Verenice', last: 'Voelker')
|
92
118
|
end
|
93
119
|
|
94
120
|
it 'should format correctly' do
|
95
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
121
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Verenice')
|
122
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
123
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
96
124
|
end
|
97
125
|
end
|
98
126
|
|
99
127
|
context 'with [:middle, :suffix]' do
|
100
128
|
before do
|
101
|
-
@name = Nomen
|
129
|
+
@name = Nomen.new(middle: 'Verenice', suffix: 'M.D.')
|
102
130
|
end
|
103
131
|
|
104
132
|
it 'should format correctly' do
|
105
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
133
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Verenice M.D.')
|
134
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
135
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
106
136
|
end
|
107
137
|
end
|
108
138
|
|
109
139
|
context 'with [:last, :suffix]' do
|
110
140
|
before do
|
111
|
-
@name = Nomen
|
141
|
+
@name = Nomen.new(last: 'Voelker', suffix: 'M.D.')
|
112
142
|
end
|
113
143
|
|
114
144
|
it 'should format correctly' do
|
115
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
145
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, M.D.')
|
146
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
147
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
116
148
|
end
|
117
149
|
end
|
118
150
|
|
119
151
|
context 'with [:first]' do
|
120
152
|
before do
|
121
|
-
@name = Nomen
|
153
|
+
@name = Nomen.new(first: 'Katya')
|
122
154
|
end
|
123
155
|
|
124
156
|
it 'should format correctly' do
|
125
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
157
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Katya')
|
158
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
159
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
126
160
|
end
|
127
161
|
end
|
128
162
|
|
129
163
|
context 'with [:middle]' do
|
130
164
|
before do
|
131
|
-
@name = Nomen
|
165
|
+
@name = Nomen.new(middle: 'Verenice')
|
132
166
|
end
|
133
167
|
|
134
168
|
it 'should format correctly' do
|
135
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
169
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Verenice')
|
170
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
171
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
136
172
|
end
|
137
173
|
end
|
138
174
|
|
139
175
|
context 'with [:last]' do
|
140
176
|
before do
|
141
|
-
@name = Nomen
|
177
|
+
@name = Nomen.new(last: 'Voelker')
|
142
178
|
end
|
143
179
|
|
144
180
|
it 'should format correctly' do
|
145
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
181
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker')
|
182
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
183
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
146
184
|
end
|
147
185
|
end
|
148
186
|
|
149
187
|
context 'with [:suffix]' do
|
150
188
|
before do
|
151
|
-
@name = Nomen
|
189
|
+
@name = Nomen.new(suffix: 'M.D.')
|
152
190
|
end
|
153
191
|
|
154
192
|
it 'should format correctly' do
|
155
|
-
expect(Nomen::Formatters::Inverted.format(@name)).to
|
193
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('M.D.')
|
194
|
+
expect(Nomen::Formatters::Inverted.format(nils(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
195
|
+
expect(Nomen::Formatters::Inverted.format(blanks(@name))).to eq(Nomen::Formatters::Inverted.format(@name))
|
156
196
|
end
|
157
197
|
end
|
158
198
|
end
|
data/spec/nomen_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Nomen do
|
4
|
+
context 'initialization' do
|
5
|
+
it 'should accept no parameters' do
|
6
|
+
expect{Nomen.new}.not_to raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should ignore non-name segment hash parameters' do
|
10
|
+
name = Nomen.new(first: 'Katya', foo: 'bar')
|
11
|
+
expect(name).to eq(Nomen.new(first: 'Katya'))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should only accept one parameter' do
|
15
|
+
expect{Nomen.new({last: 'Voelker'}, 'foo')}.to raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'equality' do
|
20
|
+
it 'should match equality based on name segment matching' do
|
21
|
+
a = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker')
|
22
|
+
b = Nomen.new(last: 'Voelker', middle: 'Verenice', first: 'Katya')
|
23
|
+
expect(a).to eq(b)
|
24
|
+
expect(b).to eq(a)
|
25
|
+
a.suffix = "M.D."
|
26
|
+
expect(a).not_to eq(b)
|
27
|
+
expect(b).not_to eq(a)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'formatting' do
|
32
|
+
it 'should defer formatting to the proper format object' do
|
33
|
+
a = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
34
|
+
expect(a.format(:inverted)).to eq(Nomen::Formatters::Inverted.format(a))
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should default to the :full formatter' do
|
38
|
+
a = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
39
|
+
expect(a.format).to eq(a.format(:full))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'to_h' do
|
44
|
+
it 'should convert to hash using FRAGMENTS' do
|
45
|
+
full = Nomen.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
46
|
+
expect(full.to_h).to eq({first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.'})
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should save empty fragments as null values' do
|
50
|
+
first = Nomen.new(first: 'Katya')
|
51
|
+
expect(first.to_h).to eq({first: 'Katya', middle: nil, last: nil, suffix: nil})
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nomen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abe Voelker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,14 +69,13 @@ files:
|
|
69
69
|
- lib/nomen/formatters.rb
|
70
70
|
- lib/nomen/formatters/full.rb
|
71
71
|
- lib/nomen/formatters/inverted.rb
|
72
|
-
- lib/nomen/name.rb
|
73
72
|
- lib/nomen/version.rb
|
74
73
|
- nomen.gemspec
|
75
74
|
- spec/formatters/formatters_helper.rb
|
76
75
|
- spec/formatters/full_spec.rb
|
77
76
|
- spec/formatters/inverted_spec.rb
|
78
77
|
- spec/formatters_spec.rb
|
79
|
-
- spec/
|
78
|
+
- spec/nomen_spec.rb
|
80
79
|
- spec/spec_helper.rb
|
81
80
|
homepage: https://github.com/abevoelker/nomen
|
82
81
|
licenses:
|
@@ -88,12 +87,12 @@ require_paths:
|
|
88
87
|
- lib
|
89
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
89
|
requirements:
|
91
|
-
- -
|
90
|
+
- - '>='
|
92
91
|
- !ruby/object:Gem::Version
|
93
92
|
version: '0'
|
94
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
94
|
requirements:
|
96
|
-
- -
|
95
|
+
- - '>='
|
97
96
|
- !ruby/object:Gem::Version
|
98
97
|
version: '0'
|
99
98
|
requirements: []
|
@@ -107,5 +106,5 @@ test_files:
|
|
107
106
|
- spec/formatters/full_spec.rb
|
108
107
|
- spec/formatters/inverted_spec.rb
|
109
108
|
- spec/formatters_spec.rb
|
110
|
-
- spec/
|
109
|
+
- spec/nomen_spec.rb
|
111
110
|
- spec/spec_helper.rb
|
data/lib/nomen/name.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Nomen
|
2
|
-
class Name
|
3
|
-
attr_accessor :first, :middle, :last, :suffix
|
4
|
-
|
5
|
-
def initialize(opts={})
|
6
|
-
name_opts = opts.select{|k,v| [:first, :middle, :last, :suffix].include?(k)}
|
7
|
-
name_opts.each{|k,v| send("#{k}=".to_sym, v)}
|
8
|
-
self
|
9
|
-
end
|
10
|
-
|
11
|
-
def format(type=:full)
|
12
|
-
Nomen::Formatters.lookup(type).format(self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def ==(other)
|
16
|
-
[:first, :middle, :last, :suffix].each do |m|
|
17
|
-
return false if self.send(m) != other.send(m)
|
18
|
-
end
|
19
|
-
true
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
data/spec/name_spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe Nomen::Name do
|
4
|
-
context 'initialization' do
|
5
|
-
it 'should accept no parameters' do
|
6
|
-
expect{Nomen::Name.new}.not_to raise_error
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should ignore non-name segment hash parameters' do
|
10
|
-
name = Nomen::Name.new(first: 'Katya', foo: 'bar')
|
11
|
-
expect(name).to eq(Nomen::Name.new(first: 'Katya'))
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should only accept one parameter' do
|
15
|
-
expect{Nomen::Name.new({last: 'Voelker'}, 'foo')}.to raise_error
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'equality' do
|
20
|
-
it 'should match equality based on name segment matching' do
|
21
|
-
a = Nomen::Name.new(first: 'Katya', middle: 'Verenice', last: 'Voelker')
|
22
|
-
b = Nomen::Name.new(last: 'Voelker', middle: 'Verenice', first: 'Katya')
|
23
|
-
expect(a).to eq(b)
|
24
|
-
expect(b).to eq(a)
|
25
|
-
a.suffix = "M.D."
|
26
|
-
expect(a).not_to eq(b)
|
27
|
-
expect(b).not_to eq(a)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'formatting' do
|
32
|
-
it 'should defer formatting to the proper format object' do
|
33
|
-
a = Nomen::Name.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
34
|
-
expect(a.format(:inverted)).to eq(Nomen::Formatters::Inverted.format(a))
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should default to the :full formatter' do
|
38
|
-
a = Nomen::Name.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
39
|
-
expect(a.format).to eq(a.format(:full))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|