person-name 0.2.8 → 0.2.9
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/VERSION +1 -1
- data/lib/person_name/has_person_name.rb +23 -2
- data/spec/person_name/has_person_name_spec.rb +24 -0
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.9
|
|
@@ -111,11 +111,13 @@ module PersonName
|
|
|
111
111
|
|
|
112
112
|
existing_part_fields = []
|
|
113
113
|
part_values = []
|
|
114
|
+
part_hash = {}
|
|
114
115
|
PersonName::NameSplitter::NAME_PARTS.each do |name_part|
|
|
115
116
|
test_field = "#{name_base}_#{name_part}"
|
|
116
117
|
if attributes.has_key? test_field
|
|
117
118
|
existing_part_fields << test_field
|
|
118
119
|
part_values << attributes[test_field]
|
|
120
|
+
part_hash[name_part.to_sym] = attributes[test_field]
|
|
119
121
|
else
|
|
120
122
|
part_values << send(test_field.to_sym)
|
|
121
123
|
end
|
|
@@ -123,8 +125,27 @@ module PersonName
|
|
|
123
125
|
if part_values.compact.join(" ") == full
|
|
124
126
|
attributes.delete name_base
|
|
125
127
|
else
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
# try to use existing fields as editing values of full name
|
|
129
|
+
new_part_values = PersonName::NameSplitter.split(attributes[name_base], part_hash)
|
|
130
|
+
assignments_valid = nil
|
|
131
|
+
|
|
132
|
+
# test if there is no conflict
|
|
133
|
+
PersonName::NameSplitter::NAME_PARTS.each do |name_part|
|
|
134
|
+
test_field = "#{name_base}_#{name_part}"
|
|
135
|
+
if attributes.has_key? test_field
|
|
136
|
+
attributes[test_field] = new_part_values[name_part.to_sym]
|
|
137
|
+
assignments_valid = true if assignments_valid.nil?
|
|
138
|
+
else
|
|
139
|
+
assignments_valid = false unless new_part_values[name_part.to_sym].nil?
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
if assignments_valid
|
|
144
|
+
attributes.delete name_base
|
|
145
|
+
else
|
|
146
|
+
existing_part_fields.each do |part_field|
|
|
147
|
+
attributes.delete part_field
|
|
148
|
+
end
|
|
128
149
|
end
|
|
129
150
|
end
|
|
130
151
|
end
|
|
@@ -148,6 +148,30 @@ describe "Has Person Name" do
|
|
|
148
148
|
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
+
it "should use the individual fields as edit post attributes match almost" do
|
|
152
|
+
@person = NamePerson.new
|
|
153
|
+
@person.attributes = {
|
|
154
|
+
:name => "Yolanthe Truuske Cabau van Kasbergen",
|
|
155
|
+
:name_first_name => "Yolanthe",
|
|
156
|
+
:name_middle_name => nil,
|
|
157
|
+
:name_last_name => "Cabau van Kasbergen"
|
|
158
|
+
}
|
|
159
|
+
@person.name.to_s.should == "Yolanthe Truuske Cabau van Kasbergen"
|
|
160
|
+
@person.name.last_name.should == "Cabau van Kasbergen"
|
|
161
|
+
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "should use the aggregated field if the posted attributes are not all available" do
|
|
165
|
+
@person = NamePerson.new
|
|
166
|
+
@person.attributes = {
|
|
167
|
+
:name => "Henk de Slager",
|
|
168
|
+
:name_first_name => "Henk",
|
|
169
|
+
:name_last_name => "Zanger"
|
|
170
|
+
}
|
|
171
|
+
@person.name.to_s.should == "Henk de Slager"
|
|
172
|
+
@person.name.full_last_name.should == "de Slager"
|
|
173
|
+
|
|
174
|
+
end
|
|
151
175
|
|
|
152
176
|
end
|
|
153
177
|
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: person-name
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 5
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 2
|
|
9
|
-
-
|
|
10
|
-
version: 0.2.
|
|
9
|
+
- 9
|
|
10
|
+
version: 0.2.9
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Matthijs Groen
|