nomen 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +30 -0
- data/Rakefile +12 -0
- data/lib/nomen.rb +3 -0
- data/lib/nomen/formatters.rb +15 -0
- data/lib/nomen/formatters/full.rb +24 -0
- data/lib/nomen/formatters/inverted.rb +28 -0
- data/lib/nomen/name.rb +23 -0
- data/lib/nomen/version.rb +3 -0
- data/nomen.gemspec +22 -0
- data/spec/formatters/formatters_helper.rb +1 -0
- data/spec/formatters/full_spec.rb +159 -0
- data/spec/formatters/inverted_spec.rb +159 -0
- data/spec/formatters_spec.rb +13 -0
- data/spec/name_spec.rb +42 -0
- data/spec/spec_helper.rb +9 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 02f10575d1beff1b8eacf5b2c0caf3a79cf9f244
|
4
|
+
data.tar.gz: 1ee6f8c5ab00ba4eaf0dad83721b5db4c32598cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a6dd75a601cc5c1a647c80fa1652b0a8c6694ca618438c85b00f19102789eff8a30eef5181803366830d8ac7e03a72bae23e765be9a4b8dd69f5961303099b1
|
7
|
+
data.tar.gz: 798ac89b09e2d2995dd72a1510e6fab87adc50b68a2cc5ca2737383f27e1897ae6849e0c35a3fb3cc33c484aeb891285a5db502648d7431fbe3b43f5d519abb9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Abe Voelker
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Nomen [![Build Status](https://secure.travis-ci.org/abevoelker/nomen.png)](http://travis-ci.org/abevoelker/nomen)
|
2
|
+
|
3
|
+
Simple library for formatting (and maybe later, parsing) human names.
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
The name is latin for "name"; no misandry intended. For now I'm only handling
|
8
|
+
my current use case, which is very basic formatting of American-style names.
|
9
|
+
|
10
|
+
I am aware of the [complexity of][patio11] human names.
|
11
|
+
|
12
|
+
## Synopsis
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'nomen'
|
16
|
+
|
17
|
+
n = Nomen::Name.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
18
|
+
n.format # => "Katya Verenice Voelker M.D."
|
19
|
+
n.format(:inverted) # => "Voelker, Katya Verenice M.D."
|
20
|
+
n.middle = nil
|
21
|
+
n.format # => "Katya Voelker M.D."
|
22
|
+
n.format(:inverted) # => "Voelker, Katya M.D."
|
23
|
+
```
|
24
|
+
|
25
|
+
## Copyright
|
26
|
+
|
27
|
+
Copyright (c) 2013 Abe Voelker. Released under the terms of the MIT license.
|
28
|
+
See LICENSE for details.
|
29
|
+
|
30
|
+
[patio11]: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/
|
data/Rakefile
ADDED
data/lib/nomen.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Dir[File.expand_path('../formatters/*.rb', __FILE__)].each {|file| require file }
|
2
|
+
|
3
|
+
module Nomen
|
4
|
+
module Formatters
|
5
|
+
class UnknownFormatterError < StandardError; end
|
6
|
+
|
7
|
+
def self.lookup(type)
|
8
|
+
begin
|
9
|
+
const_get(type.to_s.split('_').map(&:capitalize).join)
|
10
|
+
rescue NameError
|
11
|
+
raise UnknownFormatterError, "unknown formatter '#{type}'"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Nomen
|
2
|
+
module Formatters
|
3
|
+
class Full
|
4
|
+
|
5
|
+
def self.format(name)
|
6
|
+
String.new.tap do |str|
|
7
|
+
if name.first
|
8
|
+
str << name.first
|
9
|
+
end
|
10
|
+
if name.middle
|
11
|
+
str << (str.empty? ? name.middle : " #{name.middle}")
|
12
|
+
end
|
13
|
+
if name.last
|
14
|
+
str << (str.empty? ? name.last : " #{name.last}")
|
15
|
+
end
|
16
|
+
if name.suffix
|
17
|
+
str << (str.empty? ? name.suffix : " #{name.suffix}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Nomen
|
2
|
+
module Formatters
|
3
|
+
class Inverted
|
4
|
+
|
5
|
+
def self.format(name)
|
6
|
+
String.new.tap do |str|
|
7
|
+
if name.last
|
8
|
+
if [name.first, name.middle, name.suffix].reject(&:nil?).reject(&:empty?).any?
|
9
|
+
str << "#{name.last},"
|
10
|
+
else
|
11
|
+
str << name.last
|
12
|
+
end
|
13
|
+
end
|
14
|
+
if name.first
|
15
|
+
str << (str.empty? ? name.first : " #{name.first}")
|
16
|
+
end
|
17
|
+
if name.middle
|
18
|
+
str << (str.empty? ? name.middle : " #{name.middle}")
|
19
|
+
end
|
20
|
+
if name.suffix
|
21
|
+
str << (str.empty? ? name.suffix : " #{name.suffix}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/nomen/name.rb
ADDED
@@ -0,0 +1,23 @@
|
|
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/nomen.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/nomen/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "nomen"
|
6
|
+
s.version = Nomen::VERSION
|
7
|
+
s.authors = ['Abe Voelker']
|
8
|
+
s.email = 'abe@abevoelker.com'
|
9
|
+
s.homepage = 'https://github.com/abevoelker/nomen'
|
10
|
+
s.summary = %q{Simple human name formatter}
|
11
|
+
s.description = %q{Simple human name formatter}
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
15
|
+
s.add_development_dependency "rspec", "~> 2.14"
|
16
|
+
s.add_development_dependency "rake", "~> 10.1"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = ['test','spec','features'].map{|d| `git ls-files -- #{d}/*`.split("\n")}.flatten
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/formatters_helper'
|
2
|
+
|
3
|
+
describe Nomen::Formatters::Full do
|
4
|
+
context 'formatting a name' do
|
5
|
+
|
6
|
+
# name segment combinations were generated with
|
7
|
+
# s = [:first, :middle, :last, :suffix]; s.size.downto(1).map{|i| s.combination(i).to_a}.flatten(1)
|
8
|
+
|
9
|
+
context 'with [:first, :middle, :last, :suffix]' do
|
10
|
+
before do
|
11
|
+
@name = Nomen::Name.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should format correctly' do
|
15
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Verenice Voelker M.D.')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with [:first, :middle, :last]' do
|
20
|
+
before do
|
21
|
+
@name = Nomen::Name.new(first: 'Katya', middle: 'Verenice', last: 'Voelker')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should format correctly' do
|
25
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Verenice Voelker')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with [:first, :middle, :suffix]' do
|
30
|
+
before do
|
31
|
+
@name = Nomen::Name.new(first: 'Katya', middle: 'Verenice', suffix: 'M.D.')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should format correctly' do
|
35
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Verenice M.D.')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with [:first, :last, :suffix]' do
|
40
|
+
before do
|
41
|
+
@name = Nomen::Name.new(first: 'Katya', last: 'Voelker', suffix: 'M.D.')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should format correctly' do
|
45
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Voelker M.D.')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with [:middle, :last, :suffix]' do
|
50
|
+
before do
|
51
|
+
@name = Nomen::Name.new(middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should format correctly' do
|
55
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Verenice Voelker M.D.')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with [:first, :middle]' do
|
60
|
+
before do
|
61
|
+
@name = Nomen::Name.new(first: 'Katya', middle: 'Verenice')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should format correctly' do
|
65
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Verenice')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with [:first, :last]' do
|
70
|
+
before do
|
71
|
+
@name = Nomen::Name.new(first: 'Katya', last: 'Voelker')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should format correctly' do
|
75
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya Voelker')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with [:first, :suffix]' do
|
80
|
+
before do
|
81
|
+
@name = Nomen::Name.new(first: 'Katya', suffix: 'M.D.')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should format correctly' do
|
85
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya M.D.')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'with [:middle, :last]' do
|
90
|
+
before do
|
91
|
+
@name = Nomen::Name.new(middle: 'Verenice', last: 'Voelker')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should format correctly' do
|
95
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Verenice Voelker')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with [:middle, :suffix]' do
|
100
|
+
before do
|
101
|
+
@name = Nomen::Name.new(middle: 'Verenice', suffix: 'M.D.')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should format correctly' do
|
105
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Verenice M.D.')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'with [:last, :suffix]' do
|
110
|
+
before do
|
111
|
+
@name = Nomen::Name.new(last: 'Voelker', suffix: 'M.D.')
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should format correctly' do
|
115
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Voelker M.D.')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'with [:first]' do
|
120
|
+
before do
|
121
|
+
@name = Nomen::Name.new(first: 'Katya')
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should format correctly' do
|
125
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Katya')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'with [:middle]' do
|
130
|
+
before do
|
131
|
+
@name = Nomen::Name.new(middle: 'Verenice')
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should format correctly' do
|
135
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Verenice')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'with [:last]' do
|
140
|
+
before do
|
141
|
+
@name = Nomen::Name.new(last: 'Voelker')
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should format correctly' do
|
145
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('Voelker')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'with [:suffix]' do
|
150
|
+
before do
|
151
|
+
@name = Nomen::Name.new(suffix: 'M.D.')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should format correctly' do
|
155
|
+
expect(Nomen::Formatters::Full.format(@name)).to eq('M.D.')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/formatters_helper'
|
2
|
+
|
3
|
+
describe Nomen::Formatters::Inverted do
|
4
|
+
context 'formatting a name' do
|
5
|
+
|
6
|
+
# name segment combinations were generated with
|
7
|
+
# s = [:first, :middle, :last, :suffix]; s.size.downto(1).map{|i| s.combination(i).to_a}.flatten(1)
|
8
|
+
|
9
|
+
context 'with [:first, :middle, :last, :suffix]' do
|
10
|
+
before do
|
11
|
+
@name = Nomen::Name.new(first: 'Katya', middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should format correctly' do
|
15
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Katya Verenice M.D.')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with [:first, :middle, :last]' do
|
20
|
+
before do
|
21
|
+
@name = Nomen::Name.new(first: 'Katya', middle: 'Verenice', last: 'Voelker')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should format correctly' do
|
25
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Katya Verenice')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with [:first, :middle, :suffix]' do
|
30
|
+
before do
|
31
|
+
@name = Nomen::Name.new(first: 'Katya', middle: 'Verenice', suffix: 'M.D.')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should format correctly' do
|
35
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Katya Verenice M.D.')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with [:first, :last, :suffix]' do
|
40
|
+
before do
|
41
|
+
@name = Nomen::Name.new(first: 'Katya', last: 'Voelker', suffix: 'M.D.')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should format correctly' do
|
45
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Katya M.D.')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with [:middle, :last, :suffix]' do
|
50
|
+
before do
|
51
|
+
@name = Nomen::Name.new(middle: 'Verenice', last: 'Voelker', suffix: 'M.D.')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should format correctly' do
|
55
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Verenice M.D.')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with [:first, :middle]' do
|
60
|
+
before do
|
61
|
+
@name = Nomen::Name.new(first: 'Katya', middle: 'Verenice')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should format correctly' do
|
65
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Katya Verenice')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with [:first, :last]' do
|
70
|
+
before do
|
71
|
+
@name = Nomen::Name.new(first: 'Katya', last: 'Voelker')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should format correctly' do
|
75
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Katya')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with [:first, :suffix]' do
|
80
|
+
before do
|
81
|
+
@name = Nomen::Name.new(first: 'Katya', suffix: 'M.D.')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should format correctly' do
|
85
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Katya M.D.')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'with [:middle, :last]' do
|
90
|
+
before do
|
91
|
+
@name = Nomen::Name.new(middle: 'Verenice', last: 'Voelker')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should format correctly' do
|
95
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, Verenice')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with [:middle, :suffix]' do
|
100
|
+
before do
|
101
|
+
@name = Nomen::Name.new(middle: 'Verenice', suffix: 'M.D.')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should format correctly' do
|
105
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Verenice M.D.')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'with [:last, :suffix]' do
|
110
|
+
before do
|
111
|
+
@name = Nomen::Name.new(last: 'Voelker', suffix: 'M.D.')
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should format correctly' do
|
115
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker, M.D.')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'with [:first]' do
|
120
|
+
before do
|
121
|
+
@name = Nomen::Name.new(first: 'Katya')
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should format correctly' do
|
125
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Katya')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'with [:middle]' do
|
130
|
+
before do
|
131
|
+
@name = Nomen::Name.new(middle: 'Verenice')
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should format correctly' do
|
135
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Verenice')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'with [:last]' do
|
140
|
+
before do
|
141
|
+
@name = Nomen::Name.new(last: 'Voelker')
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should format correctly' do
|
145
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('Voelker')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'with [:suffix]' do
|
150
|
+
before do
|
151
|
+
@name = Nomen::Name.new(suffix: 'M.D.')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should format correctly' do
|
155
|
+
expect(Nomen::Formatters::Inverted.format(@name)).to eq('M.D.')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Nomen::Formatters do
|
4
|
+
context 'formatter lookup' do
|
5
|
+
it 'should return formatter object reference' do
|
6
|
+
expect(Nomen::Formatters.lookup(:full)).to eq(Nomen::Formatters::Full)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should raise an error if a formatter cannot be found' do
|
10
|
+
expect{Nomen::Formatters.lookup(:unknown)}.to raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/name_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
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
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nomen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abe Voelker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.1'
|
55
|
+
description: Simple human name formatter
|
56
|
+
email: abe@abevoelker.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- .rspec
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/nomen.rb
|
69
|
+
- lib/nomen/formatters.rb
|
70
|
+
- lib/nomen/formatters/full.rb
|
71
|
+
- lib/nomen/formatters/inverted.rb
|
72
|
+
- lib/nomen/name.rb
|
73
|
+
- lib/nomen/version.rb
|
74
|
+
- nomen.gemspec
|
75
|
+
- spec/formatters/formatters_helper.rb
|
76
|
+
- spec/formatters/full_spec.rb
|
77
|
+
- spec/formatters/inverted_spec.rb
|
78
|
+
- spec/formatters_spec.rb
|
79
|
+
- spec/name_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
homepage: https://github.com/abevoelker/nomen
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.0.6
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Simple human name formatter
|
105
|
+
test_files:
|
106
|
+
- spec/formatters/formatters_helper.rb
|
107
|
+
- spec/formatters/full_spec.rb
|
108
|
+
- spec/formatters/inverted_spec.rb
|
109
|
+
- spec/formatters_spec.rb
|
110
|
+
- spec/name_spec.rb
|
111
|
+
- spec/spec_helper.rb
|