simple_model 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -114,7 +114,32 @@ module ExtendCore
114
114
  def to_currency
115
115
  to_f.to_currency
116
116
  end
117
+
117
118
 
119
+ # Parse a full name into it's parts. http://pastie.org/867415
120
+ # Based on :http://artofmission.com/articles/2009/5/31/parse-full-names-with-ruby
121
+ #
122
+ # Options:
123
+ # +name+
124
+ # +seperate_middle_name+ defaults to true. if false, will combine middle name into last name.
125
+
126
+ def parse_name(seperate_middle_name=true)
127
+ parts = self.split # First, split the name into an array
128
+
129
+ parts.each_with_index do |part, i|
130
+ # If any part is "and", then put together the two parts around it
131
+ # For example, "Mr. and Mrs." or "Mickey and Minnie"
132
+ if part=~/^(and|&)$/i && i > 0
133
+ parts[i-1] = [parts.delete_at(i+1), parts.at(i).downcase, parts.delete_at(i-1)].reverse * " "
134
+ end
135
+ end if self=~/\s(and|&)\s/i # optimize
136
+
137
+ { :prefix => (parts.shift if parts[0]=~/^\w+\./),
138
+ :first_name => parts.shift || "", # if name is "", then atleast first_name should be ""
139
+ :suffix => (parts.pop if parts[-1]=~/(\w+\.|[IVXLM]+|[A-Z]+\.)$/),
140
+ :last_name => (seperate_middle_name ? parts.pop : parts.slice!(0..-1) * " "),
141
+ :middle_name => (parts * " " unless parts.empty?) }
142
+ end
118
143
  end
119
144
  Fixnum.class_eval do
120
145
  #Any value greater than 0 is true
@@ -1,3 +1,3 @@
1
1
  module SimpleModel
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  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.8
5
+ version: 0.1.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joshua T Mckinney
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-12 00:00:00 -06:00
13
+ date: 2011-02-21 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency