countries 0.1.5 → 0.1.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
data/countries.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{countries}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["hexorx"]
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "countries.gemspec",
27
27
  "lib/countries.rb",
28
+ "lib/countries/select_helper.rb",
28
29
  "lib/data/addresses.yaml",
29
30
  "lib/data/countries.yaml",
30
31
  "lib/data/import.rb",
data/lib/countries.rb CHANGED
@@ -1,6 +1,9 @@
1
+ require File.join(File.dirname(__FILE__), 'countries', 'select_helper.rb')
2
+
1
3
  class Country
2
4
  Data = YAML.load_file(File.join(File.dirname(__FILE__), 'data', 'countries.yaml')) || {}
3
- Names = Data.map {|code,data| data['name']}.sort
5
+ Names = Data.map {|k,v| [v['name'],k]}.sort
6
+ NameIndex = Hash[*Names.flatten]
4
7
 
5
8
  attr_reader :number, :alpha2, :alpha3, :name, :names, :latitude, :longitude, :region, :subregion, :country_code, :national_destination_code_lengths, :national_number_lengths, :international_prefix, :national_prefix
6
9
 
@@ -38,47 +41,4 @@ class Country
38
41
  def subdivisions?
39
42
  File.exist?(File.join(File.dirname(__FILE__), 'data', 'subdivisions', "#{alpha2}.yaml"))
40
43
  end
41
- end
42
-
43
- # CountrySelect - stolen from http://github.com/rails/iso-3166-country-select
44
- module ActionView
45
- module Helpers
46
- module FormOptionsHelper
47
-
48
- def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
49
- InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
50
- end
51
-
52
- def country_options_for_select(selected = nil, priority_countries = nil)
53
- country_options = ""
54
-
55
- if priority_countries
56
- country_options += options_for_select(priority_countries, selected)
57
- country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
58
- end
59
-
60
- return country_options + options_for_select(Country::Names, selected)
61
- end
62
- end
63
-
64
- class InstanceTag
65
- def to_country_select_tag(priority_countries, options, html_options)
66
- html_options = html_options.stringify_keys
67
- add_default_name_and_id(html_options)
68
- value = value(object)
69
- content_tag("select",
70
- add_options(
71
- country_options_for_select(value, priority_countries),
72
- options, value
73
- ), html_options
74
- )
75
- end
76
- end
77
-
78
- class FormBuilder
79
- def country_select(method, priority_countries = nil, options = {}, html_options = {})
80
- @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
81
- end
82
- end
83
- end
84
44
  end
@@ -0,0 +1,43 @@
1
+ # CountrySelect - stolen from http://github.com/rails/iso-3166-country-select
2
+ module ActionView
3
+ module Helpers
4
+ module FormOptionsHelper
5
+
6
+ def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
7
+ InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
8
+ end
9
+
10
+ def country_options_for_select(selected = nil, priority_countries = nil)
11
+ country_options = ""
12
+
13
+ if priority_countries
14
+ priority_countries.map! {|x| [x,Country::NamesIndex[x]] }
15
+ country_options += options_for_select(priority_countries, selected)
16
+ country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
17
+ end
18
+
19
+ return country_options + options_for_select(Country::Names, selected)
20
+ end
21
+ end
22
+
23
+ class InstanceTag
24
+ def to_country_select_tag(priority_countries, options, html_options)
25
+ html_options = html_options.stringify_keys
26
+ add_default_name_and_id(html_options)
27
+ value = value(object)
28
+ content_tag("select",
29
+ add_options(
30
+ country_options_for_select(value, priority_countries),
31
+ options, value
32
+ ), html_options
33
+ )
34
+ end
35
+ end
36
+
37
+ class FormBuilder
38
+ def country_select(method, priority_countries = nil, options = {}, html_options = {})
39
+ @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
40
+ end
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: countries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - hexorx
@@ -50,6 +50,7 @@ files:
50
50
  - VERSION
51
51
  - countries.gemspec
52
52
  - lib/countries.rb
53
+ - lib/countries/select_helper.rb
53
54
  - lib/data/addresses.yaml
54
55
  - lib/data/countries.yaml
55
56
  - lib/data/import.rb