happy_phone_number 0.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.
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ Happy Phone Number [![Build Status](https://travis-ci.org/lkdjiin/happy_phone_number.png)](https://travis-ci.org/lkdjiin/happy_phone_number)
2
+ ================
3
+
4
+ Description
5
+ ----------------------
6
+ A rails plugin to happily format phone numbers.
7
+
8
+ **Early stage. Work in progress.**
9
+
10
+ Overview
11
+ -----------------------
12
+
13
+ Let's say you have a `Contact` model with a `phone` attribute. The phone number
14
+ **must be save** without spaces, or hyphen, or dots...
15
+
16
+ To display the phone number you could do this:
17
+
18
+ <%= @contact.phone %>
19
+ #=> "0123456789"
20
+
21
+ Using *Happy Phone Number* you could do that:
22
+
23
+ <%= @contact.happy_phone(:fr) %>
24
+ #=> "01 23 45 67 89"
25
+
26
+ Or in uppercase if you prefer:
27
+
28
+ <%= @contact.happy_phone(:FR) %>
29
+ #=> "01 23 45 67 89"
30
+
31
+ If you want an international format:
32
+
33
+ <%= @contact.happy_phone(:international) %>
34
+ #=> "+33 1 23 45 67 89"
35
+
36
+ What if you want dots as separator?
37
+
38
+ <%= @contact.happy_phone(:fr, '.') %>
39
+ #=> "01.23.45.67.89"
40
+
41
+ What if your model have several phone attributes, like `phone1`, `phone2`
42
+ and `mobile`, or maybe `portable`?
43
+
44
+ <%= @contact.happy_phone1(:fr) %>
45
+ #=> "11 11 11 11 11"
46
+ <%= @contact.happy_phone2(:fr) %>
47
+ #=> "22 22 22 22 22"
48
+ <%= @contact.happy_mobile(:fr) %>
49
+ #=> "33 33 33 33 33"
50
+ ...
51
+
52
+
53
+ Install
54
+ -------------------------
55
+
56
+ Add this line in your Gemfile:
57
+
58
+ gem 'happy_phone_number', :git => 'git://github.com/lkdjiin/happy_phone_number.git'
59
+
60
+
61
+ Usage
62
+ --------------------------
63
+
64
+ Add the `happy_phone_number` method in your model. Example:
65
+
66
+ class Contact < ActiveRecord::Base
67
+ attr_accessible :email, :name, :phone, :fax
68
+ happy_phone_number
69
+ end
70
+
71
+ Now, in your views, you can use:
72
+
73
+ happy_phone(:fr)
74
+ happy_fax(:fr)
75
+
76
+ Dependencies
77
+ --------------------------
78
+
79
+ ruby >= 1.9.2
80
+ rails >= 3.2
81
+
82
+ License
83
+ --------------------------
84
+
85
+ MIT
86
+
87
+
88
+ Questions and/or Comments
89
+ --------------------------
90
+
91
+ Feel free to email [Xavier Nayrac](mailto:xavier.nayrac@gmail.com)
92
+ with any questions.
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'HappyPhoneNumber'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,46 @@
1
+ module HappyPhoneNumber
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+
6
+ end
7
+
8
+ module ClassMethods
9
+ def happy_phone_number(options = {})
10
+ # your code will go here
11
+ end
12
+ end
13
+
14
+ def method_missing(meth, *args, &block)
15
+ if meth.to_s =~ /^happy_(.+)$/
16
+ run_happy($1, *args, &block)
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def respond_to?(meth, include_private = false)
23
+ if meth.to_s =~ /^happy_.*$/
24
+ true
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def run_happy(meth, *args, &block)
33
+ type = args[0]
34
+ separator = args[1] || ' '
35
+ if (type == :fr) || (type == :FR)
36
+ send(meth.to_sym).unpack('A2A2A2A2A2').join(separator)
37
+ elsif type == :international
38
+ "+33#{send(meth.to_sym)[1, 9]}".unpack('A3A1A2A2A2A2').join(separator)
39
+ else
40
+ send(meth.to_sym)
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ ActiveRecord::Base.send :include, HappyPhoneNumber
@@ -0,0 +1,3 @@
1
+ module HappyPhoneNumber
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :happy_phone_number do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: happy_phone_number
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Xavier Nayrac
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.13
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Rails plugin to format phone number.
63
+ email:
64
+ - xavier.nayrac@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/happy_phone_number/version.rb
70
+ - lib/tasks/happy_phone_number_tasks.rake
71
+ - lib/happy_phone_number.rb
72
+ - MIT-LICENSE
73
+ - Rakefile
74
+ - README.markdown
75
+ homepage: https://github.com/lkdjiin/happy_phone_number
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.25
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Rails plugin to format phone number.
99
+ test_files: []