formatted_phone_number 0.1.0 → 0.1.1
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/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}")
|