big-phoney 0.0.5 → 0.0.6

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/big-phoney.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{big-phoney}
5
- s.version = "0.0.5"
5
+ s.version = "0.0.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Pat Nakajima", "Brandon Keene"]
9
9
  s.date = %q{2010-08-26}
10
- s.files = ["LICENSE", "README.md", "big-phoney.gemspec", "lib/big-phoney.rb", "lib/big_phoney.rb", "lib/big_phoney/phone_number.rb", "lib/big_phoney/.gitignore", "spec/big_phoney_spec.rb", "spec/spec_helper.rb"]
10
+ s.files = ["LICENSE", "README.md", "big-phoney.gemspec", "lib/big-phoney.rb", "lib/big_phoney.rb", "lib/big_phoney/rails.rb", "lib/big_phoney/phone_number.rb", "rails/init.rb", "lib/big_phoney/.gitignore", "spec/big_phoney_spec.rb", "spec/spec_helper.rb"]
11
11
  s.require_paths = ["lib"]
12
12
  s.rubygems_version = %q{1.3.7}
13
13
  s.summary = %q{Simple phone number parsing in Ruby}
@@ -0,0 +1,33 @@
1
+ module BigPhoney
2
+ module Rails
3
+ module ActiveRecord
4
+ def phone_number_fields(*fields)
5
+ fields.each do |field|
6
+ define_method("#{field}=") do |value|
7
+ return true if value.blank?
8
+ just_digits = value.to_s.gsub(/[^\d]/, "")
9
+ self[field] = (value.starts_with?("1") ? just_digits[1..-1] : just_digits)
10
+ end
11
+ end
12
+ end
13
+
14
+ def validate_phone(*args)
15
+ args.each do |attribute|
16
+ validate do |record|
17
+ number = record.send(attribute)
18
+
19
+ if number and not [1].include?(BigPhoney::PhoneNumber.new(number).country_code.to_i)
20
+ record.errors[attribute] << "must be a valid US phone number"
21
+ end
22
+
23
+ if number and not BigPhoney::PhoneNumber.new(number).valid?
24
+ record.errors[attribute] << "is not valid"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ ActiveRecord::Base.extend(BigPhoney::Rails::ActiveRecord)
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'big_phoney/rails'
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,17 @@
1
1
  require 'rubygems'
2
2
 
3
+ begin
4
+ require 'temping'
5
+ rescue LoadError
6
+ puts "Temping is need to run tests."
7
+ puts ""
8
+ puts "$ gem install temping"
9
+ puts
10
+ puts "BYE!"
11
+ end
12
+
13
+ include Temping
14
+
3
15
  begin
4
16
  require 'spec'
5
17
  rescue LoadError
@@ -7,4 +19,3 @@ rescue LoadError
7
19
  end
8
20
 
9
21
  require File.dirname(__FILE__) + '/../lib/big_phoney'
10
-
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big-phoney
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pat Nakajima
@@ -34,7 +34,9 @@ files:
34
34
  - big-phoney.gemspec
35
35
  - lib/big-phoney.rb
36
36
  - lib/big_phoney.rb
37
+ - lib/big_phoney/rails.rb
37
38
  - lib/big_phoney/phone_number.rb
39
+ - rails/init.rb
38
40
  - lib/big_phoney/.gitignore
39
41
  - spec/big_phoney_spec.rb
40
42
  - spec/spec_helper.rb