simple_phone_number 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ Manifest
2
+ README.md
3
+ Rakefile
4
+ init.rb
5
+ lib/simple_phone_number.rb
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # SimplePhoneNumber
2
+
3
+ ## Install
4
+
5
+ gem install simple_phone_number
6
+
7
+ ## Example
8
+
9
+ SimplePhoneNumber will accept the following phone formats:
10
+ 1234567890, 123-456-7890, 123.456.7890, 123 456 7890 and (123) 456 7890
11
+
12
+ and save the record in 123-456-7890 format
13
+
14
+ class User < ActiveRecord::Base
15
+ simple_phone_number :home_phone, :cell_phone
16
+ end
17
+
18
+ ## Options
19
+
20
+
21
+ simple_phone_number :home_phone, :validate => false, :allow_blank => true
22
+ simple_phone_number :home_phone, :validate_on => :update, :validate_if => proc{|record| record.something?}
23
+ simple_phone_number :home_phone, :validation_message => "should look like 1234567890, 123-456-7890, 123.456.7890, 123 456 7890 or (123) 456 7890"
24
+
25
+ Also,
26
+
27
+ validates_simple_phone_number :cell_phone, :if => proc{|record| record.home_phone.blank?}
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('simple_phone_number', '0.1.8') do |p|
6
+ p.description = "Validate and set phone number format"
7
+ p.url = "http://github.com/akennedy/simple_phone_number"
8
+ p.author = 'Andrew Kennedy'
9
+ p.email = 'andrew@jackrussellsoftware.com'
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'simple_phone_number'
@@ -0,0 +1,63 @@
1
+ module SimplePhoneNumber
2
+
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ attr_accessor :phone_number_attributes
9
+
10
+ def simple_phone_number(*args)
11
+ @phone_number_attributes = [] unless @phone_number_attributes.is_a? Array
12
+
13
+ options = args.extract_options!
14
+ attributes = args
15
+ attributes << :phone_number if attributes.empty?
16
+
17
+ unless options[:validate] === false
18
+ validates_simple_phone_number attributes, options
19
+ end
20
+
21
+ attributes.each do |attribute|
22
+ define_method "#{attribute}=" do |value|
23
+ phone = value.gsub(/^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/, '\1-\2-\3')
24
+ write_attribute(attribute, phone)
25
+ end
26
+
27
+ @phone_number_attributes << attribute
28
+ end
29
+
30
+ include SimplePhoneNumber::InstanceMethods
31
+ end
32
+
33
+ def phone_number_attributes
34
+ Array(@phone_number_attributes)
35
+ end
36
+
37
+ def validates_simple_phone_number(*args)
38
+ options = clean_simple_phone_number_options(args.extract_options!)
39
+ message = options.delete(:message)
40
+ attributes = args
41
+
42
+ validates_each attributes, options do |record, attr_name, value|
43
+ record.errors.add attr_name, message || 'should look like 1234567890, 123-456-7890, 123.456.7890, 123 456 7890 or (123) 456 7890' unless record[attr_name] =~ /^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
44
+ end
45
+ end
46
+
47
+ private
48
+ def clean_simple_phone_number_options(options = {})
49
+ options.inject({}) do |opts, (key, value)|
50
+ opts[key.to_s.sub(/^validat(es?|ion)_/, '').to_sym] = value
51
+ opts
52
+ end
53
+ end
54
+ end
55
+
56
+ module InstanceMethods
57
+ def phone_numbers
58
+ self.class.phone_number_attributes.map {|a| [a, read_attribute(a)]}
59
+ end
60
+ end
61
+ end
62
+
63
+ ActiveRecord::Base.send(:include, SimplePhoneNumber)
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{simple_phone_number}
5
+ s.version = "0.1.8"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Andrew Kennedy"]
9
+ s.cert_chain = ["/Users/andrew/gems/gem-public_cert.pem"]
10
+ s.date = %q{2011-01-13}
11
+ s.description = %q{Validate and set phone number format}
12
+ s.email = %q{andrew@jackrussellsoftware.com}
13
+ s.extra_rdoc_files = ["README.md", "lib/simple_phone_number.rb"]
14
+ s.files = ["Manifest", "README.md", "Rakefile", "init.rb", "lib/simple_phone_number.rb", "simple_phone_number.gemspec"]
15
+ s.homepage = %q{http://github.com/akennedy/simple_phone_number}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Simple_phone_number", "--main", "README.md"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{simple_phone_number}
19
+ s.rubygems_version = %q{1.3.6}
20
+ s.signing_key = %q{/Users/andrew/gems/gem-private_key.pem}
21
+ s.summary = %q{Validate and set phone number format}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_phone_number
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 8
9
+ version: 0.1.8
10
+ platform: ruby
11
+ authors:
12
+ - Andrew Kennedy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDSjCCAjKgAwIBAgIBADANBgkqhkiG9w0BAQUFADBLMQ8wDQYDVQQDDAZhbmRy
19
+ ZXcxIzAhBgoJkiaJk/IsZAEZFhNqYWNrcnVzc2VsbHNvZnR3YXJlMRMwEQYKCZIm
20
+ iZPyLGQBGR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E-----
37
+
38
+ date: 2011-01-13 00:00:00 -05:00
39
+ default_executable:
40
+ dependencies: []
41
+
42
+ description: Validate and set phone number format
43
+ email: andrew@jackrussellsoftware.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - README.md
50
+ - lib/simple_phone_number.rb
51
+ files:
52
+ - Manifest
53
+ - README.md
54
+ - Rakefile
55
+ - init.rb
56
+ - lib/simple_phone_number.rb
57
+ - simple_phone_number.gemspec
58
+ has_rdoc: true
59
+ homepage: http://github.com/akennedy/simple_phone_number
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --line-numbers
65
+ - --inline-source
66
+ - --title
67
+ - Simple_phone_number
68
+ - --main
69
+ - README.md
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 1
85
+ - 2
86
+ version: "1.2"
87
+ requirements: []
88
+
89
+ rubyforge_project: simple_phone_number
90
+ rubygems_version: 1.3.6
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Validate and set phone number format
94
+ test_files: []
95
+
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ���K�e��A5#��HYM��[�+=N�|���t?46��iR4��'�ǔ�$K�_9���qK�ی��JJ�H<��o/��[qfXI)z����~)�0˻Y��0���[T��Hp|��
2
+ ݖ���HW�U��ׁ��rz�/��/����f0>d�ʐ�L�}̙$�y))�i ���;��n�x0��F�I%�`�� �Y��bBW��}m=�4��H,�,�£��5c:n��R�+�'Ų{?��2(^�V咰��;�c_�