jakewendt-phonify_string 1.0.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/README.rdoc +29 -0
- data/lib/phonify_string.rb +46 -0
- metadata +68 -0
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= PhonifyString
|
2
|
+
|
3
|
+
PhonifyString generates a virtual attribute with the suffix of '_number' to be used in forms and such. On save, the contents are parsed into a phone number format like (123)456-7890 and saved in the original attribute.
|
4
|
+
|
5
|
+
== Attempting Gemification with Jeweler
|
6
|
+
|
7
|
+
vi Rakefile
|
8
|
+
rake version:write
|
9
|
+
rake gemspec
|
10
|
+
rake install
|
11
|
+
|
12
|
+
rake version:major:bump
|
13
|
+
rake release
|
14
|
+
|
15
|
+
== Options
|
16
|
+
|
17
|
+
:required (default: true)
|
18
|
+
-
|
19
|
+
|
20
|
+
|
21
|
+
== Example
|
22
|
+
|
23
|
+
class Store < ActiveRecord::Base
|
24
|
+
phonify_string :primary_phone, :secondary_phone, :required => true
|
25
|
+
end
|
26
|
+
|
27
|
+
Add controller/view usage ...
|
28
|
+
|
29
|
+
Copyright (c) 2008 [George 'Jake' Wendt III (upillar.com)], released under the MIT license
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module PhonifyString
|
2
|
+
|
3
|
+
def phonify_string(*names)
|
4
|
+
configuration = {
|
5
|
+
:required => false
|
6
|
+
}.merge(names.extract_options!)
|
7
|
+
|
8
|
+
names.each do |name|
|
9
|
+
|
10
|
+
self.send(:attr_accessor, "#{name}_invalid".intern )
|
11
|
+
|
12
|
+
if self.accessible_attributes
|
13
|
+
self.send(:attr_accessible, "#{name}_number".intern )
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method "#{name}_number" do
|
17
|
+
read_attribute(name) unless read_attribute(name).nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method "#{name}_number=" do |phone|
|
21
|
+
if ( !phone.blank? )
|
22
|
+
if phone =~ /\D*(\d?)\D*(\d{3})\D*(\d{3})\D*(\d{4})\D*/
|
23
|
+
write_attribute(name, "#{$1}(#{$2})#{$3}-#{$4}")
|
24
|
+
instance_variable_set("@#{name}_invalid", false)
|
25
|
+
else
|
26
|
+
write_attribute(name, phone)
|
27
|
+
instance_variable_set("@#{name}_invalid", true)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
if configuration[:required]
|
31
|
+
write_attribute(name,'')
|
32
|
+
instance_variable_set("@#{name}_invalid", true)
|
33
|
+
else
|
34
|
+
write_attribute(name,'')
|
35
|
+
instance_variable_set("@#{name}_invalid", false)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
validates_each( name ) do |record,attr,value|
|
41
|
+
record.errors.add("#{name}_number","is invalid.") if record.send("#{name}_invalid".intern)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jakewendt-phonify_string
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jake
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-17 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: longer description of your gem
|
23
|
+
email: github@jake.otherinbox.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- lib/phonify_string.rb
|
32
|
+
- README.rdoc
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/jakewendt/phonify_string
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.7
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: one-line summary of your gem
|
67
|
+
test_files: []
|
68
|
+
|