simple_model 0.1.9 → 0.2.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.
@@ -1,3 +1,4 @@
1
+
1
2
  module ExtendCore
2
3
  require 'time'
3
4
  require 'date'
@@ -124,7 +125,15 @@ module ExtendCore
124
125
  # +seperate_middle_name+ defaults to true. if false, will combine middle name into last name.
125
126
 
126
127
  def parse_name(seperate_middle_name=true)
127
- parts = self.split # First, split the name into an array
128
+ str = self
129
+ if str.include?(',') # Rearrange names formatted as Doe, John C. to John C. Doe
130
+ temp = str.split(',')
131
+ temp << temp[0]
132
+ temp.delete_at(0)
133
+ str = temp.join(" ")
134
+
135
+ end
136
+ parts = str.split # First, split the name into an array
128
137
 
129
138
  parts.each_with_index do |part, i|
130
139
  # If any part is "and", then put together the two parts around it
@@ -136,7 +145,7 @@ module ExtendCore
136
145
 
137
146
  { :prefix => (parts.shift if parts[0]=~/^\w+\./),
138
147
  :first_name => parts.shift || "", # if name is "", then atleast first_name should be ""
139
- :suffix => (parts.pop if parts[-1]=~/(\w+\.|[IVXLM]+|[A-Z]+\.)$/),
148
+ :suffix => (parts.pop if parts[-1]=~/(\w+\.|[IVXLM]+|[A-Z]+\.|(?i)jr|(?i)sr )$/),
140
149
  :last_name => (seperate_middle_name ? parts.pop : parts.slice!(0..-1) * " "),
141
150
  :middle_name => (parts * " " unless parts.empty?) }
142
151
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleModel
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -83,4 +83,20 @@ describe ExtendCore, 'String.rb' do
83
83
  end
84
84
  end
85
85
 
86
+ describe ExtendCore, 'parse_name' do
87
+ it "return return hash with name elements properly keyed" do
88
+ hash = "Doe, John C.".parse_name
89
+ hash[:first_name].should eql("John")
90
+ hash[:last_name].should eql("Doe")
91
+
92
+ hash = "John Doe".parse_name
93
+ hash[:first_name].should eql("John")
94
+ hash[:last_name].should eql("Doe")
95
+
96
+ hash = "Mr. John C. Doe Jr".parse_name
97
+ hash[:first_name].should eql("John")
98
+ hash[:last_name].should eql("Doe")
99
+
100
+ end
101
+ end
86
102
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_model
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.9
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joshua T Mckinney