formatted_phone_number 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new("formatted_phone_number", '0.1.
|
5
|
+
Echoe.new("formatted_phone_number", '0.1.1') do |p|
|
6
6
|
p.description = "Phone number handler for ActiveRecord models"
|
7
7
|
p.url = "http://github.com/jonohrt/formatted_phone_number"
|
8
8
|
p.author = "Jon Ohrt"
|
@@ -10,6 +10,10 @@ module FormattedPhoneNumber
|
|
10
10
|
self.send 'cattr_accessor', :phone_column
|
11
11
|
self.instance_eval do
|
12
12
|
self.phone_column = phone_number_column
|
13
|
+
define_method "formatted_#{self.phone_column}" do
|
14
|
+
phone_array = self.send(self.phone_column).split("-")
|
15
|
+
return "(#{phone_array[0]}) #{phone_array[1]}-#{phone_array[2]}"
|
16
|
+
end
|
13
17
|
end
|
14
18
|
include InstanceMethods
|
15
19
|
end
|
@@ -26,7 +30,9 @@ module FormattedPhoneNumber
|
|
26
30
|
def phone_suffix
|
27
31
|
self.send(self.class.phone_column).split('-')[2] if self.send(self.class.phone_column)
|
28
32
|
end
|
29
|
-
|
33
|
+
|
34
|
+
private
|
35
|
+
|
30
36
|
def update_phone_number
|
31
37
|
if @phone_area_code && @phone_prefix && @phone_suffix
|
32
38
|
self.update_attribute(self.class.phone_column.to_sym, "#{@phone_area_code}-#{@phone_prefix}-#{@phone_suffix}")
|