uncharted 0.0.6 → 0.0.7.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +20 -0
- data/README.md +2 -0
- data/Rakefile +4 -0
- data/lib/uncharted/country.rb +12 -4
- data/lib/uncharted/{adapters → extensions}/mongoid.rb +0 -0
- data/lib/uncharted/extensions/rails.rb +74 -0
- data/lib/uncharted/territory.rb +17 -14
- data/lib/uncharted/version.rb +1 -1
- data/lib/uncharted.rb +2 -1
- data/test/country_test.rb +13 -2
- metadata +13 -12
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
0.0.7 (2011-08-31)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
New Featires:
|
5
|
+
|
6
|
+
- Country select helper
|
7
|
+
- Territory select helper
|
8
|
+
|
9
|
+
Other Changes:
|
10
|
+
|
11
|
+
- Refactoring
|
12
|
+
|
13
|
+
0.0.6 (2011-08-31)
|
14
|
+
------------------
|
15
|
+
|
16
|
+
Project Changes:
|
17
|
+
|
18
|
+
- Test Coverage added
|
19
|
+
- Project Maintenance
|
20
|
+
|
1
21
|
0.0.5 (2011-08-31)
|
2
22
|
------------------
|
3
23
|
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require 'rake/clean'
|
2
3
|
require 'rake/testtask'
|
3
4
|
require 'yard'
|
4
5
|
|
@@ -13,6 +14,9 @@ YARD::Rake::YardocTask.new do |t|
|
|
13
14
|
t.options
|
14
15
|
end
|
15
16
|
|
17
|
+
CLEAN.include %w(coverage doc pkg tmp .yardoc)
|
16
18
|
|
17
19
|
desc "Run tests"
|
18
20
|
task :default => :test
|
21
|
+
|
22
|
+
|
data/lib/uncharted/country.rb
CHANGED
@@ -8,7 +8,7 @@ module Uncharted
|
|
8
8
|
@alpha2 = alpha2
|
9
9
|
@alpha3 = alpha3
|
10
10
|
@name = name
|
11
|
-
self.class.
|
11
|
+
self.class.data[alpha2] = self
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_s
|
@@ -19,13 +19,21 @@ module Uncharted
|
|
19
19
|
countries.count
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.find(
|
23
|
-
|
22
|
+
def self.find(codes)
|
23
|
+
if codes.is_a? Array
|
24
|
+
return codes.collect {|c| data[c]}
|
25
|
+
end
|
26
|
+
data[codes]
|
24
27
|
end
|
25
28
|
|
26
29
|
def self.countries
|
27
|
-
@
|
30
|
+
@data.values
|
28
31
|
end
|
32
|
+
|
33
|
+
def self.data
|
34
|
+
@data ||= {}
|
35
|
+
end
|
36
|
+
|
29
37
|
|
30
38
|
end
|
31
39
|
|
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# CountrySelect
|
2
|
+
module ActionView
|
3
|
+
module Helpers
|
4
|
+
module FormOptionsHelper
|
5
|
+
|
6
|
+
# Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
|
7
|
+
def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
|
8
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
|
12
|
+
# have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
|
13
|
+
# that they will be listed above the rest of the (long) list.
|
14
|
+
#
|
15
|
+
# NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
|
16
|
+
def country_options_for_select(selected = nil, priority_countries = nil)
|
17
|
+
country_options = ""
|
18
|
+
|
19
|
+
if priority_countries
|
20
|
+
country_options += options_from_collection_for_select(Country.find(priority_countries), :alpha2, :name, selected)
|
21
|
+
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
|
22
|
+
# prevents selected from being included twice in the HTML which causes
|
23
|
+
# some browsers to select the second selected option (not priority)
|
24
|
+
# which makes it harder to select an alternative priority country
|
25
|
+
selected = nil if priority_countries.include?(selected)
|
26
|
+
end
|
27
|
+
country_options + options_from_collection_for_select(Uncharted::Country.countries, :alpha2, :name, selected)
|
28
|
+
end
|
29
|
+
|
30
|
+
def territory_options_for_select(selected = nil, priority_territories = nil)
|
31
|
+
territory_options = ""
|
32
|
+
|
33
|
+
if priority_territories
|
34
|
+
territory_options += options_from_collection_for_select(Territory.find(priority_territories), :alpha2, :name, selected)
|
35
|
+
territory_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
|
36
|
+
# prevents selected from being included twice in the HTML which causes
|
37
|
+
# some browsers to select the second selected option (not priority)
|
38
|
+
# which makes it harder to select an alternative priority country
|
39
|
+
selected = nil if priority_territories.include?(selected)
|
40
|
+
end
|
41
|
+
territory_options + options_from_collection_for_select(Uncharted::Country.territories, :alpha2, :name, selected)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class InstanceTag
|
47
|
+
|
48
|
+
def to_country_select_tag(priority_countries, options, html_options)
|
49
|
+
html_options = html_options.stringify_keys
|
50
|
+
add_default_name_and_id(html_options)
|
51
|
+
value = value(object)
|
52
|
+
content_tag("select", add_options(country_options_for_select(value, priority_countries), options, value), html_options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_territory_select_tag(priority_territories, options, html_options)
|
56
|
+
html_options = html_options.stringify_keys
|
57
|
+
add_default_name_and_id(html_options)
|
58
|
+
value = value(object)
|
59
|
+
content_tag("select", add_options(territory_options_for_select(value, priority_territories), options, value), html_options)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class FormBuilder
|
64
|
+
|
65
|
+
def country_select(method, priority_countries = nil, options = {}, html_options = {})
|
66
|
+
@template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
|
67
|
+
end
|
68
|
+
|
69
|
+
def territory_select(method, priority_territories = nil, options = {}, html_options = {})
|
70
|
+
@template.territory_select(@object_name, method, priority_territories, options.merge(:object => @object), html_options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/uncharted/territory.rb
CHANGED
@@ -5,40 +5,43 @@ module Uncharted
|
|
5
5
|
class Country
|
6
6
|
|
7
7
|
def subdivisions
|
8
|
-
@subdivisions ||=
|
8
|
+
@subdivisions ||= []
|
9
9
|
end
|
10
10
|
|
11
11
|
def territories
|
12
|
-
|
12
|
+
@territories ||= find_by_type(:territory)
|
13
13
|
end
|
14
14
|
|
15
15
|
def states
|
16
|
-
|
16
|
+
@states ||= find_by_type(:state)
|
17
17
|
end
|
18
18
|
|
19
19
|
def districts
|
20
|
-
|
20
|
+
@districts ||= find_by_type(:district)
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.subdivisions
|
24
|
-
Territory.
|
24
|
+
Territory.data
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_by_type(type)
|
28
|
+
subdivisions.select {|t| t.type == type}
|
25
29
|
end
|
26
30
|
|
27
31
|
end
|
28
32
|
|
29
33
|
class Territory
|
30
34
|
|
31
|
-
attr_reader :abbr, :code, :country, :country_code, :name, :
|
35
|
+
attr_reader :abbr, :code, :country, :country_code, :name, :type
|
32
36
|
|
33
|
-
def initialize(code,
|
37
|
+
def initialize(code, type, name)
|
34
38
|
@code = code
|
35
|
-
@
|
39
|
+
@type = type
|
36
40
|
@name = name
|
37
41
|
@country_code, @abbr = code.split('-')
|
38
42
|
@country = Country.find(@country_code)
|
39
|
-
Territory.
|
40
|
-
@country.subdivisions
|
41
|
-
@country.subdivisions[@division] << self
|
43
|
+
Territory.data[code] = self
|
44
|
+
@country.subdivisions << self if @country
|
42
45
|
end
|
43
46
|
|
44
47
|
def to_s
|
@@ -46,11 +49,11 @@ module Uncharted
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def self.find(code)
|
49
|
-
|
52
|
+
data[code]
|
50
53
|
end
|
51
54
|
|
52
|
-
def self.
|
53
|
-
@
|
55
|
+
def self.data
|
56
|
+
@data ||= {}
|
54
57
|
end
|
55
58
|
|
56
59
|
end
|
data/lib/uncharted/version.rb
CHANGED
data/lib/uncharted.rb
CHANGED
@@ -6,7 +6,8 @@ require 'uncharted/territory'
|
|
6
6
|
require 'uncharted/data/countries'
|
7
7
|
require 'uncharted/data/br'
|
8
8
|
|
9
|
-
require 'uncharted/
|
9
|
+
require 'uncharted/extensions/mongoid'
|
10
|
+
require 'uncharted/extensions/rails'
|
10
11
|
|
11
12
|
Country = Uncharted::Country
|
12
13
|
Territory = Uncharted::Territory
|
data/test/country_test.rb
CHANGED
@@ -15,6 +15,11 @@ class TestCountry < MiniTest::Unit::TestCase
|
|
15
15
|
assert_equal 'BRA', @br.alpha3
|
16
16
|
assert_equal 'Brazil', @br.name
|
17
17
|
end
|
18
|
+
|
19
|
+
def test_country_find
|
20
|
+
@us = Country.find('US')
|
21
|
+
assert_equal [@br, @us], Country.find([@br.alpha2, @us.alpha2])
|
22
|
+
end
|
18
23
|
|
19
24
|
def test_to_s
|
20
25
|
assert_equal 'BR', @br.to_s
|
@@ -26,13 +31,15 @@ class TestCountry < MiniTest::Unit::TestCase
|
|
26
31
|
end
|
27
32
|
|
28
33
|
def test_territories
|
29
|
-
|
34
|
+
df = Territory.find('BR-DF')
|
35
|
+
assert_equal [df], @br.districts
|
30
36
|
assert_equal 26, @br.states.count
|
37
|
+
assert_equal 27, @br.subdivisions.count
|
31
38
|
assert @br.territories.empty?
|
32
39
|
|
33
|
-
assert_equal [:district, :state], @br.subdivisions.keys.sort
|
34
40
|
assert_equal 'Paraná', Uncharted::Territory.find('BR-PR').name
|
35
41
|
assert_equal 'PR', Uncharted::Territory.find('BR-PR').abbr
|
42
|
+
assert_equal 'PR', Uncharted::Territory.find('BR-PR').to_s
|
36
43
|
end
|
37
44
|
|
38
45
|
def test_classes
|
@@ -41,5 +48,9 @@ class TestCountry < MiniTest::Unit::TestCase
|
|
41
48
|
assert_equal Country::Field, Uncharted::Country::Field
|
42
49
|
assert_equal Territory::Field, Uncharted::Territory::Field
|
43
50
|
end
|
51
|
+
|
52
|
+
def test_country_collection
|
53
|
+
assert_equal 247, Country.countries.count
|
54
|
+
end
|
44
55
|
|
45
56
|
end
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uncharted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7.beta1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gilson Ferraz
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160168080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2160168080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: purdytest
|
27
|
-
requirement: &
|
27
|
+
requirement: &2160155840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2160155840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yard
|
38
|
-
requirement: &
|
38
|
+
requirement: &2160143640 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2160143640
|
47
47
|
description: Provide ISO 3166 codes and english name for countries and their political
|
48
48
|
divisions
|
49
49
|
email:
|
@@ -60,10 +60,11 @@ files:
|
|
60
60
|
- README.md
|
61
61
|
- Rakefile
|
62
62
|
- lib/uncharted.rb
|
63
|
-
- lib/uncharted/adapters/mongoid.rb
|
64
63
|
- lib/uncharted/country.rb
|
65
64
|
- lib/uncharted/data/br.rb
|
66
65
|
- lib/uncharted/data/countries.rb
|
66
|
+
- lib/uncharted/extensions/mongoid.rb
|
67
|
+
- lib/uncharted/extensions/rails.rb
|
67
68
|
- lib/uncharted/territory.rb
|
68
69
|
- lib/uncharted/version.rb
|
69
70
|
- test/country_test.rb
|
@@ -86,9 +87,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
88
|
none: false
|
88
89
|
requirements:
|
89
|
-
- - ! '
|
90
|
+
- - ! '>'
|
90
91
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
92
|
+
version: 1.3.1
|
92
93
|
requirements: []
|
93
94
|
rubyforge_project:
|
94
95
|
rubygems_version: 1.8.10
|