has_contact_number 0.1.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ffbc27af06a9ce3aa4bba728fd3fd108916f5503
4
- data.tar.gz: 5729a354b6244a8d56f1a042dd2fe13ba163a59a
2
+ SHA256:
3
+ metadata.gz: 5d056ae179d5898609de13d5b73010177dbb06f2c3adea1947e308480d366334
4
+ data.tar.gz: 139f8bedf15eb4f3a5475c69094da19d9d283313dca38110fdd0ec60aefdf5f7
5
5
  SHA512:
6
- metadata.gz: 387dd6edce276bb6af1fa9e9e1156df4e85211a408488984bb79f2bae95f5403546dc07fb339eec77dd6430c8b751e48ba2aafa6a674072d81990b9bf1aa80ff
7
- data.tar.gz: 58f1bf86989806033a3850e4eab3f5c223a3a0eda89d0974925f5d6394956b85295011983e2179defbb2bc3af759cfb858afd47305a315a6e6ff684c5c1e0282
6
+ metadata.gz: 5d289a54bbce761715d0b8fbbb690cd206caa1162a30ce03102093e4792eb006c28f179047cd1f62049e976d5fcfac1e06888f3802a2233d4923bc4bfbccb3f8
7
+ data.tar.gz: e123155db191afc408839d81d6806058ae31b14d40cde2e4d4e1d1b70109335aecf78237c420977876defbd77c00d3687a5231156e7866a0b0fe896a93d09cf7
@@ -1,13 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
  module ActionView::Helpers::FormOptionsHelper
3
3
 
4
- puts '------------------------------------HasContactNumber::HelperMethods---------------------'
5
- def options_for_isd_code_select
6
- @isd_code_options ||= IsoCountryCodes.all.map do |record|
7
-
8
- [record.calling_code, record.calling_code.delete('+').rjust(4, '0')]
4
+ OPTIONS_FOR_ISD_CODES_SELECT = IsoCountryCodes.all.map{ |icc|
5
+ {
6
+ code: icc.calling_code,
7
+ code_to_i: icc.calling_code.delete('+').to_i,
8
+ code_to_db: icc.calling_code.delete('+').rjust(4, '0'),
9
+ country: icc.name,
10
+ country_with_code: "#{icc.name} (#{icc.calling_code})"
11
+ }
12
+ }
13
+ OPTIONS_FOR_ISD_CODES_SELECT_BY_CODE = OPTIONS_FOR_ISD_CODES_SELECT.uniq.sort_by{|record| record[:code_to_i]}.map do |record|
14
+ [record[:code], record[:code_to_db]]
15
+ end
16
+ OPTIONS_FOR_ISD_CODES_SELECT_BY_COUNTRY_NAME = OPTIONS_FOR_ISD_CODES_SELECT.sort_by{|record| record[:country]}.map do |record|
17
+ [record[:country_with_code], record[:code_to_db]]
18
+ end
9
19
 
10
- end
20
+ def options_for_isd_code_select(display_country_names: true)
21
+ display_country_names ? OPTIONS_FOR_ISD_CODES_SELECT_BY_COUNTRY_NAME : OPTIONS_FOR_ISD_CODES_SELECT_BY_CODE
11
22
  end
12
23
 
13
24
  end
@@ -2,7 +2,6 @@
2
2
  module HasContactNumber::ModelMethods
3
3
 
4
4
  extend ActiveSupport::Concern
5
- puts '---------------------HasContactNumber::ModelMethods---------------------'
6
5
  module ClassMethods
7
6
 
8
7
  def contact_number_attributes(*columns)
@@ -21,16 +20,22 @@ module HasContactNumber::ModelMethods
21
20
  @#{column}_isd_code ||= #{column} && #{column}[0..3]
22
21
  end
23
22
 
23
+ def #{column}_isd_code=(val)
24
+ @#{column}_isd_code = val
25
+ self.#{column} = "\#{val}\#{#{column}_without_isd_code}"
26
+ end
27
+
24
28
  def #{column}_without_isd_code
25
29
  @#{column}_without_isd_code ||= #{column} && #{column}[4..-1]
26
30
  end
27
31
 
28
- before_validation { |model|
29
- model.#{column} = model.#{column}_isd_code + model.#{column}_without_isd_code
30
- }
32
+ def #{column}_without_isd_code=(val)
33
+ @#{column}_without_isd_code = val
34
+ self.#{column} = "\#{#{column}_isd_code}\#{val}"
35
+ end
31
36
 
32
- validates :#{column}_isd_code, presence: true, if: '#{column}_without_isd_code.present?'
33
- validates :#{column}_without_isd_code, presence: true, if: '#{column}_isd_code.present?'
37
+ validates :#{column}_isd_code, presence: true, if: proc { |model| model.#{column}_without_isd_code.present? }
38
+ validates :#{column}_without_isd_code, presence: true, if: proc { |model| model.#{column}_isd_code.present? }
34
39
  validates :#{column}, phony_plausible: true, if: proc { |model|
35
40
  model.#{column}_isd_code.present? && model.#{column}_without_isd_code.present?
36
41
  }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module HasContactNumber
3
3
 
4
- VERSION = '0.1.0'
4
+ VERSION = '0.4.0'
5
5
 
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_contact_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anand Bait
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-09 00:00:00.000000000 Z
11
+ date: 2021-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iso_country_codes
@@ -124,8 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.5.1
127
+ rubygems_version: 3.2.7
129
128
  signing_key:
130
129
  specification_version: 4
131
130
  summary: Phone, mobile, fax numbers with ISD code storage and validation.