From 9b5e93f51263b0c190efdd1f19f8b4ece151b7af Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Tue, 12 May 2015 12:45:39 +0200 Subject: [PATCH 01/13] Add support for continents and their structure --- .gitignore | 1 + carmen.gemspec | 1 + .../territories/territoryContainment.json | 180 ++++++++++++++++++ lib/carmen.rb | 9 + lib/carmen/continent.rb | 66 +++++++ lib/carmen/country.rb | 4 + lib/carmen/world.rb | 6 +- locale/continents/de.yml | 33 ++++ locale/continents/en.yml | 33 ++++ spec/carmen/continent_spec.rb | 72 +++++++ spec/carmen/country_spec.rb | 6 + spec/carmen/world_spec.rb | 4 + spec/spec_helper.rb | 2 + spec_data/locale/en/continents.yml | 17 ++ .../territories/territoryContainment.json | 28 +++ 15 files changed, 461 insertions(+), 1 deletion(-) create mode 100644 iso_data/territories/territoryContainment.json create mode 100644 lib/carmen/continent.rb create mode 100644 locale/continents/de.yml create mode 100644 locale/continents/en.yml create mode 100644 spec/carmen/continent_spec.rb create mode 100644 spec_data/locale/en/continents.yml create mode 100644 spec_data/territories/territoryContainment.json diff --git a/.gitignore b/.gitignore index 88c0374d..1fa3c14c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ tmp .bundle/* Gemfile.lock .rvmrc +.ruby-gemset diff --git a/carmen.gemspec b/carmen.gemspec index a961bb87..f7e27482 100644 --- a/carmen.gemspec +++ b/carmen.gemspec @@ -20,5 +20,6 @@ Gem::Specification.new do |s| s.add_development_dependency('nokogiri') s.add_development_dependency('rake', '0.9.2.2') s.add_development_dependency('i18n') + s.add_development_dependency 'pry-byebug' s.add_dependency('activesupport', '>= 3.0.0') end diff --git a/iso_data/territories/territoryContainment.json b/iso_data/territories/territoryContainment.json new file mode 100644 index 00000000..5ed0565f --- /dev/null +++ b/iso_data/territories/territoryContainment.json @@ -0,0 +1,180 @@ +{ + "territoryContainment": [ + { + "territory": "001", + "contains": "019 002 150 142 009" + }, + { + "territory": "011", + "contains": "BF BJ CI CV GH GM GN GW LR ML MR NE NG SH SL SN TG" + }, + { + "territory": "013", + "contains": "BZ CR GT HN MX NI PA SV" + }, + { + "territory": "014", + "contains": "BI DJ ER ET KE KM MG MU MW MZ RE RW SC SO TZ UG YT ZM ZW" + }, + { + "territory": "142", + "contains": "145 143 030 034 035" + }, + { + "territory": "143", + "contains": "TM TJ KG KZ UZ" + }, + { + "territory": "145", + "contains": "AE AM AZ BH CY GE IL IQ JO KW LB OM PS QA SA SY TR YE" + }, + { + "territory": "145", + "contains": "NT YD", + "status": "deprecated" + }, + { + "territory": "015", + "contains": "DZ EG EH LY MA SD SS TN EA IC" + }, + { + "territory": "150", + "contains": "154 155 151 039" + }, + { + "territory": "150", + "contains": "EU", + "status": "grouping" + }, + { + "territory": "150", + "contains": "QU", + "status": "deprecated" + }, + { + "territory": "151", + "contains": "BG BY CZ HU MD PL RO RU SK UA" + }, + { + "territory": "154", + "contains": "GG IM JE AX DK EE FI FO GB IE IS LT LV NO SE SJ" + }, + { + "territory": "155", + "contains": "AT BE CH DE FR LI LU MC NL" + }, + { + "territory": "155", + "contains": "DD FX", + "status": "deprecated" + }, + { + "territory": "017", + "contains": "AO CD CF CG CM GA GQ ST TD" + }, + { + "territory": "017", + "contains": "ZR", + "status": "deprecated" + }, + { + "territory": "018", + "contains": "BW LS NA SZ ZA" + }, + { + "territory": "019", + "contains": "021 013 029 005" + }, + { + "territory": "019", + "contains": "003 419", + "status": "grouping" + }, + { + "territory": "002", + "contains": "015 011 017 014 018" + }, + { + "territory": "021", + "contains": "BM CA GL PM US" + }, + { + "territory": "029", + "contains": "AG AI AW BB BL BQ BS CU CW DM DO GD GP HT JM KN KY LC MF MQ MS PR SX TC TT VC VG VI" + }, + { + "territory": "029", + "contains": "AN", + "status": "deprecated" + }, + { + "territory": "003", + "contains": "021 013 029", + "grouping": "true" + }, + { + "territory": "030", + "contains": "CN HK JP KP KR MN MO TW" + }, + { + "territory": "035", + "contains": "BN ID KH LA MM MY PH SG TH TL VN" + }, + { + "territory": "035", + "contains": "BU TP", + "status": "deprecated" + }, + { + "territory": "039", + "contains": "AD AL BA ES GI GR HR IT ME MK MT RS PT SI SM VA XK" + }, + { + "territory": "039", + "contains": "CS YU", + "status": "deprecated" + }, + { + "territory": "419", + "contains": "013 029 005", + "grouping": "true" + }, + { + "territory": "005", + "contains": "AR BO BR CL CO EC FK GF GY PE PY SR UY VE" + }, + { + "territory": "053", + "contains": "AU NF NZ" + }, + { + "territory": "054", + "contains": "FJ NC PG SB VU" + }, + { + "territory": "057", + "contains": "FM GU KI MH MP NR PW" + }, + { + "territory": "061", + "contains": "AS CK NU PF PN TK TO TV WF WS" + }, + { + "territory": "034", + "contains": "AF BD BT IN IR LK MV NP PK" + }, + { + "territory": "009", + "contains": "053 054 057 061 QO" + }, + { + "territory": "QO", + "contains": "AQ BV CC CX GS HM IO TF UM AC CP DG TA" + }, + { + "territory": "EU", + "contains": "AT BE CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU LV MT NL PL PT SE SI SK BG RO", + "grouping": "true" + } + ] +} \ No newline at end of file diff --git a/lib/carmen.rb b/lib/carmen.rb index 64ba142f..961e36bc 100644 --- a/lib/carmen.rb +++ b/lib/carmen.rb @@ -4,6 +4,7 @@ lib_path = File.expand_path('../../lib', __FILE__) $LOAD_PATH.unshift(lib_path) +require 'carmen/continent' require 'carmen/country' require 'carmen/i18n' require 'carmen/version' @@ -39,6 +40,14 @@ def i18n_backend @i18n_backend end + def territories_path=(path) + @territories_path = path + end + + def territories_path + @territories_path || (Carmen.root_path + 'iso_data/territories/territoryContainment.json') + end + # Public: set an object to use as the I18n backend. # # Ths suppiled object must respond to t(key). diff --git a/lib/carmen/continent.rb b/lib/carmen/continent.rb new file mode 100644 index 00000000..4b898b07 --- /dev/null +++ b/lib/carmen/continent.rb @@ -0,0 +1,66 @@ +require 'carmen/country' + +module Carmen + class Continent + + attr_reader :continent_code + attr_reader :parent + + def initialize(data={}, parent=nil) + @continent_code = data['territory'] + @contains = data['contains'].split(' ') + @parent = parent + end + + def name + Carmen.i18n_backend.translate("continents.#{self.continent_code}.name") + end + + def sub_continents + contained_continents_or_countries.select { |continent_or_country| continent_or_country.is_a? Continent } + end + + def countries + if sub_continents.any? + sub_continents.map { |c| c.countries }.flatten + else + contained_continents_or_countries.select { |continent_or_country| continent_or_country.is_a? Country } + end + end + + def self.coded(code) + Continent.all.detect { |c| c.continent_code == code } + end + + def self.all + continents + end + + def world? + continent_code == "001" + end + + private + + def contained_continents_or_countries + @contains.map { |c| code_to_object(c) } + end + + def code_to_object(code) + if /\d\d\d/.match(code) + Continent.coded(code) + elsif /[A-Z][A-Z]/.match(code) + Country.coded(code) + end + end + + def self.continents + @continents ||= load_territory_containment.map { |tc| Continent.new(tc) } + end + + def self.load_territory_containment + JSON.parse(File.read(Carmen.territories_path))["territoryContainment"] + end + + end +end \ No newline at end of file diff --git a/lib/carmen/country.rb b/lib/carmen/country.rb index 57c02a4b..445d3c8e 100644 --- a/lib/carmen/country.rb +++ b/lib/carmen/country.rb @@ -20,6 +20,10 @@ def initialize(data={}, parent=nil) super end + def continent + Carmen::Continent.all.detect { |c| c.sub_continents.empty? && c.countries.include?(self) } + end + def common_name Carmen.i18n_backend.translate(path('common_name')) end diff --git a/lib/carmen/world.rb b/lib/carmen/world.rb index 3287cd11..76452135 100644 --- a/lib/carmen/world.rb +++ b/lib/carmen/world.rb @@ -1,5 +1,5 @@ require 'singleton' - +require 'json' require 'carmen/region' module Carmen @@ -17,6 +17,10 @@ def subregion_class Country end + def continents + Continent.all.detect { |c| c.world? }.sub_continents + end + def path 'world' end diff --git a/locale/continents/de.yml b/locale/continents/de.yml new file mode 100644 index 00000000..0a18f525 --- /dev/null +++ b/locale/continents/de.yml @@ -0,0 +1,33 @@ +--- +de: + continents: + 001: "Welt" + 002: "Afrika" + 003: "Nordamerika" + 005: "Südamerika" + 009: "Ozeanien" + 011: "Westafrika" + 013: "Mittelamerika" + 014: "Ostafrika" + 015: "Nordafrika" + 017: "Zentralafrika" + 018: "Südafrika" + 019: "Amerika" + 021: "Nordamerika" + 029: "Karibik" + 030: "Ostasien" + 034: "Südasien" + 035: "Südostasien" + 039: "Südeuropa" + 053: "Australien und Neuseeland" + 054: "Melanesien" + 057: "Mikronesien" + 061: "Polynesia" + 419: "Lateinamerika und die Karibik" + 142: "Asien" + 143: "Zentralasien" + 145: "Westasien" + 150: "Europa" + 151: "Osteuropa" + 154: "Nordeuropa" + 155: "Westeuropa" \ No newline at end of file diff --git a/locale/continents/en.yml b/locale/continents/en.yml new file mode 100644 index 00000000..c351d3c3 --- /dev/null +++ b/locale/continents/en.yml @@ -0,0 +1,33 @@ +--- +en: + continents: + 001: 'World' + 002: 'Africa' + 003: 'North America' + 005: 'South America' + 009: 'Oceania' + 011: 'Western Africa' + 013: 'Central America' + 014: 'Eastern Africa' + 015: 'Northern Africa' + 017: 'Middle Africa' + 018: 'Southern Africa' + 019: 'Americas' + 021: 'Northern America' + 029: 'Caribbean' + 030: 'Eastern Asia' + 034: 'Southern Asia' + 035: 'South-Eastern Asia' + 039: 'Southern Europe' + 053: 'Australia and New Zealand' + 054: 'Melanesia' + 057: 'Micronesia' + 061: 'Polynesia' + 419: 'Latin America and the Caribbean' + 142: 'Asia' + 143: 'Central Asia' + 145: 'Western Asia' + 150: 'Europe' + 151: 'Eastern Europe' + 154: 'Northern Europe' + 155: 'Western Europe' \ No newline at end of file diff --git a/spec/carmen/continent_spec.rb b/spec/carmen/continent_spec.rb new file mode 100644 index 00000000..ef656c42 --- /dev/null +++ b/spec/carmen/continent_spec.rb @@ -0,0 +1,72 @@ +require 'spec_helper' + +describe Carmen::Continent do + + describe "#initialize when given a string of contained-country-codes" do + + it "will interpret them as carmen-countries and set them as contained_continents_or_countries" do + continent = Carmen::Continent.new({'territory' => '001', 'contains' => '002 003 004'}) + + continent.sub_continents.count.must_equal 3 + continent.sub_continents[0].class.must_equal Carmen::Continent + continent.sub_continents[1].class.must_equal Carmen::Continent + continent.sub_continents[2].class.must_equal Carmen::Continent + end + end + + describe "#initialize when given a string of contained-continent-codes" do + it "will interpret them as carmen-continents and set them as contained_continents_or_countries" do + continent = Carmen::Continent.new({'territory' => '011', 'contains' => 'OC EU'}) + + continent.countries.count.must_equal 2 + continent.countries[0].class.must_equal Carmen::Country + continent.countries[1].class.must_equal Carmen::Country + end + end + + describe '#coded' do + it 'gets the continent with the given code' do + continent = Carmen::Continent.coded('003') + continent.name.must_equal 'Waterworld' + continent.continent_code.must_equal '003' + + continent.sub_continents.count.must_equal 2 + continent.countries.count.must_equal 0 + end + end + + describe '#name' do + it 'uses the i18n-backend to fetch the correct name' do + continent = Carmen::Continent.coded('002') + continent.name.must_equal 'Junglolia' + + continent = Carmen::Continent.coded('003') + continent.name.must_equal 'Waterworld' + end + end + + describe '#sub_continents' do + it 'returns the sub_continents of the given continent' do + Carmen::Continent.coded('001').sub_continents.count.must_equal 2 + Carmen::Continent.coded('001').sub_continents[0].continent_code.must_equal "002" + Carmen::Continent.coded('001').sub_continents[1].continent_code.must_equal "003" + end + end + + describe '#countries' do + it 'returns the countries of the given continent if NO sub_continents are present' do + Carmen::Continent.coded('004').countries.count.must_equal 3 + end + + it 'finds all countries of all sub_continents if some are present' do + Carmen::Continent.coded('001').countries.count.must_equal 3 + end + end + + describe '#all' do + it 'returns all existing continents of all hierachies' do + Carmen::Continent.all.count.must_equal 6 + end + end + +end diff --git a/spec/carmen/country_spec.rb b/spec/carmen/country_spec.rb index 38b54f56..b4a7727e 100644 --- a/spec/carmen/country_spec.rb +++ b/spec/carmen/country_spec.rb @@ -40,6 +40,12 @@ eurasia.instance_of?(Carmen::Country).must_equal true end + describe '#continent' do + it 'provides access to the continent it belongs to' do + Carmen::Country.coded('OC').continent.must_equal Carmen::Continent.coded('004') + end + end + describe "basic attributes" do before do @oceania = Carmen::Country.coded('OC') diff --git a/spec/carmen/world_spec.rb b/spec/carmen/world_spec.rb index 48b3a419..c9be99ba 100644 --- a/spec/carmen/world_spec.rb +++ b/spec/carmen/world_spec.rb @@ -10,4 +10,8 @@ Carmen::World.instance.subregions.size.must_equal(3) end + it 'has 2 continents' do + Carmen::World.instance.continents.size.must_equal(2) + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1c25cb93..79c62fa5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,11 +3,13 @@ require 'minitest/autorun' require 'bundler/setup' +require 'pry-byebug' require 'carmen' def setup_carmen_test_data_path Carmen.clear_data_paths Carmen.append_data_path(carmen_spec_data_path) + Carmen.territories_path = Carmen.root_path + 'spec_data/territories/territoryContainment.json' end def setup_carmen_test_i18n_backend diff --git a/spec_data/locale/en/continents.yml b/spec_data/locale/en/continents.yml new file mode 100644 index 00000000..458ad5b4 --- /dev/null +++ b/spec_data/locale/en/continents.yml @@ -0,0 +1,17 @@ +--- +en: + continents: + '001': + name: 'World' + '002': + name: 'Junglolia' + '003': + name: 'Waterworld' + '004': + name: 'Takatukaland' + '005': + name: 'Disneyland' + '006': + name: 'Middle Earth' + '007': + name: 'Skyrim' \ No newline at end of file diff --git a/spec_data/territories/territoryContainment.json b/spec_data/territories/territoryContainment.json new file mode 100644 index 00000000..8f7088e5 --- /dev/null +++ b/spec_data/territories/territoryContainment.json @@ -0,0 +1,28 @@ +{ + "territoryContainment": [ + { + "territory": "001", + "contains": "002 003" + }, + { + "territory": "002", + "contains": "004 005" + }, + { + "territory": "003", + "contains": "006 007" + }, + { + "territory": "004", + "contains": "OC EU ES" + }, + { + "territory": "006", + "contains": "" + }, + { + "territory": "007", + "contains": "" + } + ] +} \ No newline at end of file From 9a393373243abf4b13f581494ca69a283d6ab36c Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Tue, 12 May 2015 14:03:18 +0200 Subject: [PATCH 02/13] add countries to world --- lib/carmen/world.rb | 4 ++++ spec/carmen/world_spec.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/carmen/world.rb b/lib/carmen/world.rb index 76452135..32b85e39 100644 --- a/lib/carmen/world.rb +++ b/lib/carmen/world.rb @@ -21,6 +21,10 @@ def continents Continent.all.detect { |c| c.world? }.sub_continents end + def countries + Continent.all.detect { |c| c.world? }.countries + end + def path 'world' end diff --git a/spec/carmen/world_spec.rb b/spec/carmen/world_spec.rb index c9be99ba..741d3f5b 100644 --- a/spec/carmen/world_spec.rb +++ b/spec/carmen/world_spec.rb @@ -14,4 +14,8 @@ Carmen::World.instance.continents.size.must_equal(2) end + it 'has 3 countries' do + Carmen::World.instance.countries.size.must_equal(3) + end + end From 7e4c1cd1077be38d6511c7935b3d7e98e528b43c Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Tue, 12 May 2015 15:56:04 +0200 Subject: [PATCH 03/13] corrected locale-locations --- lib/carmen/continent.rb | 10 ++--- locale/base/en/world.yml | 61 ++++++++++++++++++++++++++++++ locale/continents/de.yml | 33 ---------------- locale/continents/en.yml | 33 ---------------- locale/overlay/de/world.yml | 61 ++++++++++++++++++++++++++++++ spec/carmen/continent_spec.rb | 6 +-- spec_data/locale/en/continents.yml | 17 --------- spec_data/locale/en/world.yml | 15 ++++++++ 8 files changed, 145 insertions(+), 91 deletions(-) delete mode 100644 locale/continents/de.yml delete mode 100644 locale/continents/en.yml delete mode 100644 spec_data/locale/en/continents.yml diff --git a/lib/carmen/continent.rb b/lib/carmen/continent.rb index 4b898b07..fff0870c 100644 --- a/lib/carmen/continent.rb +++ b/lib/carmen/continent.rb @@ -3,17 +3,17 @@ module Carmen class Continent - attr_reader :continent_code + attr_reader :code attr_reader :parent def initialize(data={}, parent=nil) - @continent_code = data['territory'] + @code = data['territory'] @contains = data['contains'].split(' ') @parent = parent end def name - Carmen.i18n_backend.translate("continents.#{self.continent_code}.name") + Carmen.i18n_backend.translate("continents.#{self.code}.name") end def sub_continents @@ -29,7 +29,7 @@ def countries end def self.coded(code) - Continent.all.detect { |c| c.continent_code == code } + Continent.all.detect { |c| c.code == code } end def self.all @@ -37,7 +37,7 @@ def self.all end def world? - continent_code == "001" + code == "001" end private diff --git a/locale/base/en/world.yml b/locale/base/en/world.yml index e075697c..35208607 100644 --- a/locale/base/en/world.yml +++ b/locale/base/en/world.yml @@ -997,3 +997,64 @@ en: common_name: name: Zimbabwe official_name: Republic of Zimbabwe + continents: + "001": + name: 'World' + "002": + name: 'Africa' + "003": + name: 'North America' + "005": + name: 'South America' + "009": + name: 'Oceania' + "011": + name: 'Western Africa' + "013": + name: 'Central America' + "014": + name: 'Eastern Africa' + "015": + name: 'Northern Africa' + "017": + name: 'Middle Africa' + "018": + name: 'Southern Africa' + "019": + name: 'Americas' + "021": + name: 'Northern America' + "029": + name: 'Caribbean' + "030": + name: 'Eastern Asia' + "034": + name: 'Southern Asia' + "035": + name: 'South-Eastern Asia' + "039": + name: 'Southern Europe' + "053": + name: 'Australia and New Zealand' + "054": + name: 'Melanesia' + "057": + name: 'Micronesia' + "061": + name: 'Polynesia' + "419": + name: 'Latin America and the Caribbean' + "142": + name: 'Asia' + "143": + name: 'Central Asia' + "145": + name: 'Western Asia' + "150": + name: 'Europe' + "151": + name: 'Eastern Europe' + "154": + name: 'Northern Europe' + "155": + name: 'Western Europe' \ No newline at end of file diff --git a/locale/continents/de.yml b/locale/continents/de.yml deleted file mode 100644 index 0a18f525..00000000 --- a/locale/continents/de.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -de: - continents: - 001: "Welt" - 002: "Afrika" - 003: "Nordamerika" - 005: "Südamerika" - 009: "Ozeanien" - 011: "Westafrika" - 013: "Mittelamerika" - 014: "Ostafrika" - 015: "Nordafrika" - 017: "Zentralafrika" - 018: "Südafrika" - 019: "Amerika" - 021: "Nordamerika" - 029: "Karibik" - 030: "Ostasien" - 034: "Südasien" - 035: "Südostasien" - 039: "Südeuropa" - 053: "Australien und Neuseeland" - 054: "Melanesien" - 057: "Mikronesien" - 061: "Polynesia" - 419: "Lateinamerika und die Karibik" - 142: "Asien" - 143: "Zentralasien" - 145: "Westasien" - 150: "Europa" - 151: "Osteuropa" - 154: "Nordeuropa" - 155: "Westeuropa" \ No newline at end of file diff --git a/locale/continents/en.yml b/locale/continents/en.yml deleted file mode 100644 index c351d3c3..00000000 --- a/locale/continents/en.yml +++ /dev/null @@ -1,33 +0,0 @@ ---- -en: - continents: - 001: 'World' - 002: 'Africa' - 003: 'North America' - 005: 'South America' - 009: 'Oceania' - 011: 'Western Africa' - 013: 'Central America' - 014: 'Eastern Africa' - 015: 'Northern Africa' - 017: 'Middle Africa' - 018: 'Southern Africa' - 019: 'Americas' - 021: 'Northern America' - 029: 'Caribbean' - 030: 'Eastern Asia' - 034: 'Southern Asia' - 035: 'South-Eastern Asia' - 039: 'Southern Europe' - 053: 'Australia and New Zealand' - 054: 'Melanesia' - 057: 'Micronesia' - 061: 'Polynesia' - 419: 'Latin America and the Caribbean' - 142: 'Asia' - 143: 'Central Asia' - 145: 'Western Asia' - 150: 'Europe' - 151: 'Eastern Europe' - 154: 'Northern Europe' - 155: 'Western Europe' \ No newline at end of file diff --git a/locale/overlay/de/world.yml b/locale/overlay/de/world.yml index f37022ad..a5964d93 100644 --- a/locale/overlay/de/world.yml +++ b/locale/overlay/de/world.yml @@ -1065,3 +1065,64 @@ de: common_name: !!null name: Simbabwe official_name: !!null + continents: + "001": + name: "Welt" + "002": + name: "Afrika" + "003": + name: "Nordamerika" + "005": + name: "Südamerika" + "009": + name: "Ozeanien" + "011": + name: "Westafrika" + "013": + name: "Mittelamerika" + "014": + name: "Ostafrika" + "015": + name: "Nordafrika" + "017": + name: "Zentralafrika" + "018": + name: "Südafrika" + "019": + name: "Amerika" + "021": + name: "Nordamerika" + "029": + name: "Karibik" + "030": + name: "Ostasien" + "034": + name: "Südasien" + "035": + name: "Südostasien" + "039": + name: "Südeuropa" + "053": + name: "Australien und Neuseeland" + "054": + name: "Melanesien" + "057": + name: "Mikronesien" + "061": + name: "Polynesia" + "419": + name: "Lateinamerika und die Karibik" + "142": + name: "Asien" + "143": + name: "Zentralasien" + "145": + name: "Westasien" + "150": + name: "Europa" + "151": + name: "Osteuropa" + "154": + name: "Nordeuropa" + "155": + name: "Westeuropa" \ No newline at end of file diff --git a/spec/carmen/continent_spec.rb b/spec/carmen/continent_spec.rb index ef656c42..04b8a3fa 100644 --- a/spec/carmen/continent_spec.rb +++ b/spec/carmen/continent_spec.rb @@ -28,7 +28,7 @@ it 'gets the continent with the given code' do continent = Carmen::Continent.coded('003') continent.name.must_equal 'Waterworld' - continent.continent_code.must_equal '003' + continent.code.must_equal '003' continent.sub_continents.count.must_equal 2 continent.countries.count.must_equal 0 @@ -48,8 +48,8 @@ describe '#sub_continents' do it 'returns the sub_continents of the given continent' do Carmen::Continent.coded('001').sub_continents.count.must_equal 2 - Carmen::Continent.coded('001').sub_continents[0].continent_code.must_equal "002" - Carmen::Continent.coded('001').sub_continents[1].continent_code.must_equal "003" + Carmen::Continent.coded('001').sub_continents[0].code.must_equal "002" + Carmen::Continent.coded('001').sub_continents[1].code.must_equal "003" end end diff --git a/spec_data/locale/en/continents.yml b/spec_data/locale/en/continents.yml deleted file mode 100644 index 458ad5b4..00000000 --- a/spec_data/locale/en/continents.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -en: - continents: - '001': - name: 'World' - '002': - name: 'Junglolia' - '003': - name: 'Waterworld' - '004': - name: 'Takatukaland' - '005': - name: 'Disneyland' - '006': - name: 'Middle Earth' - '007': - name: 'Skyrim' \ No newline at end of file diff --git a/spec_data/locale/en/world.yml b/spec_data/locale/en/world.yml index b47e88c6..7e2a0ee2 100644 --- a/spec_data/locale/en/world.yml +++ b/spec_data/locale/en/world.yml @@ -13,3 +13,18 @@ en: common_name: Eastasia name: Eastasia official_name: The Superstate of Eastasia + continents: + '001': + name: 'World' + '002': + name: 'Junglolia' + '003': + name: 'Waterworld' + '004': + name: 'Takatukaland' + '005': + name: 'Disneyland' + '006': + name: 'Middle Earth' + '007': + name: 'Skyrim' \ No newline at end of file From b9eff5ab303182e43ee4d1bacf02515d0eb9f057 Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Tue, 12 May 2015 18:44:11 +0200 Subject: [PATCH 04/13] corrected requires --- lib/carmen/continent.rb | 1 + lib/carmen/world.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carmen/continent.rb b/lib/carmen/continent.rb index fff0870c..76ab08c2 100644 --- a/lib/carmen/continent.rb +++ b/lib/carmen/continent.rb @@ -1,3 +1,4 @@ +require 'json' require 'carmen/country' module Carmen diff --git a/lib/carmen/world.rb b/lib/carmen/world.rb index 32b85e39..b73bdd48 100644 --- a/lib/carmen/world.rb +++ b/lib/carmen/world.rb @@ -1,5 +1,4 @@ require 'singleton' -require 'json' require 'carmen/region' module Carmen From 623ce01fceaee911138b2df037d47b3056b2df0d Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Wed, 13 May 2015 09:23:06 +0200 Subject: [PATCH 05/13] Update README.md --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 9dafef46..676541ef 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,40 @@ Some subregions may contain additional subregions. An example of this is Spain: andalucia.subregions.first => <#Carmen::Region name="Almería" type="province"> +If you need structural data about the continents. You can start here: + + Carmen::World.continents + +This will return a `Carmen::Continent` that you can use like this: + + continent = Carmen::World.continents.first + sub_continents = continent.sub_continents + +To get the sub-continents of a given continent. Might be empty. + + countries = continent.countries + +This will give you **all countries** contained in a given continent. This will also give you countries that might be contained in sub_continents. Meaning `world.countries` will give you all countries of the world. + +Here are some examples: + + Carmen::Continent.coded('150') + => # + + Carmen::Continent.coded('150').name + => "Europe" + + Carmen::Continent.coded('150').sub_continents.map { |c| c.name } + => ["Northern Europe", "Western Europe", "Eastern Europe", "Southern Europe"] + +Of course you can also get the continent of a country be trying: + + Carmen::Country.coded('DE') + => <#Carmen::Country name="Germany"> + + Carmen::Country.coded('DE').continent.name + => "Western Europe" + ## How Carmen organizes data In order to facilitate support for I18n, Carmen stores the structure of regions From 2e1f5c1a6df148721e5294c2097e184944950ff0 Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Wed, 13 May 2015 09:37:10 +0200 Subject: [PATCH 06/13] removed debugging gems --- carmen.gemspec | 2 -- spec/spec_helper.rb | 1 - 2 files changed, 3 deletions(-) diff --git a/carmen.gemspec b/carmen.gemspec index f7e27482..892323e7 100644 --- a/carmen.gemspec +++ b/carmen.gemspec @@ -17,9 +17,7 @@ Gem::Specification.new do |s| s.files = Dir.glob("{lib,iso_data,locale}/**/*") + %w(MIT-LICENSE README.md CHANGELOG.md) s.add_development_dependency('minitest', ["= 2.6.1"]) - s.add_development_dependency('nokogiri') s.add_development_dependency('rake', '0.9.2.2') s.add_development_dependency('i18n') - s.add_development_dependency 'pry-byebug' s.add_dependency('activesupport', '>= 3.0.0') end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 79c62fa5..b41adece 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,6 @@ require 'minitest/autorun' require 'bundler/setup' -require 'pry-byebug' require 'carmen' def setup_carmen_test_data_path From 70550ec73ac6d92521341f26cfea25a591fbdce3 Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Fri, 29 May 2015 14:04:52 +0200 Subject: [PATCH 07/13] Adjusted file-structure to use YAML --- carmen.gemspec | 1 + iso_data/base/territories.yml | 148 ++++++++++++++ .../territories/territoryContainment.json | 180 ------------------ lib/carmen.rb | 2 +- lib/carmen/continent.rb | 14 +- spec/carmen/continent_spec.rb | 4 +- spec/spec_helper.rb | 3 +- spec_data/territories/territories.yml | 29 +++ .../territories/territoryContainment.json | 28 --- 9 files changed, 192 insertions(+), 217 deletions(-) create mode 100644 iso_data/base/territories.yml delete mode 100644 iso_data/territories/territoryContainment.json create mode 100644 spec_data/territories/territories.yml delete mode 100644 spec_data/territories/territoryContainment.json diff --git a/carmen.gemspec b/carmen.gemspec index 892323e7..752fdd01 100644 --- a/carmen.gemspec +++ b/carmen.gemspec @@ -19,5 +19,6 @@ Gem::Specification.new do |s| s.add_development_dependency('minitest', ["= 2.6.1"]) s.add_development_dependency('rake', '0.9.2.2') s.add_development_dependency('i18n') + s.add_development_dependency 'pry-byebug' s.add_dependency('activesupport', '>= 3.0.0') end diff --git a/iso_data/base/territories.yml b/iso_data/base/territories.yml new file mode 100644 index 00000000..4dc08e76 --- /dev/null +++ b/iso_data/base/territories.yml @@ -0,0 +1,148 @@ +--- + territoryContainment: + - + territory: "001" + contains: + - "019" + - "002" + - "150" + - "142" + - "009" + - + territory: "011" + contains: + - "BF" + - "BJ" + - "CI" + - "CV" + - "GH" + - "GM" GN GW LR ML MR NE NG SH SL SN TG" + - + territory: "013" + contains: "BZ CR GT HN MX NI PA SV" + - + territory: "014" + contains: "BI DJ ER ET KE KM MG MU MW MZ RE RW SC SO TZ UG YT ZM ZW" + - + territory: "142" + contains: "145 143 030 034 035" + - + territory: "143" + contains: "TM TJ KG KZ UZ" + - + territory: "145" + contains: "AE AM AZ BH CY GE IL IQ JO KW LB OM PS QA SA SY TR YE" + - + territory: "145" + contains: "NT YD" + status: "deprecated" + - + territory: "015" + contains: "DZ EG EH LY MA SD SS TN EA IC" + - + territory: "150" + contains: "154 155 151 039" + - + territory: "150" + contains: "EU" + status: "grouping" + - + territory: "150" + contains: "QU" + status: "deprecated" + - + territory: "151" + contains: "BG BY CZ HU MD PL RO RU SK UA" + - + territory: "154" + contains: "GG IM JE AX DK EE FI FO GB IE IS LT LV NO SE SJ" + - + territory: "155" + contains: "AT BE CH DE FR LI LU MC NL" + - + territory: "155" + contains: "DD FX" + status: "deprecated" + - + territory: "017" + contains: "AO CD CF CG CM GA GQ ST TD" + - + territory: "017" + contains: "ZR" + status: "deprecated" + - + territory: "018" + contains: "BW LS NA SZ ZA" + - + territory: "019" + contains: "021 013 029 005" + - + territory: "019" + contains: "003 419" + status: "grouping" + - + territory: "002" + contains: "015 011 017 014 018" + - + territory: "021" + contains: "BM CA GL PM US" + - + territory: "029" + contains: "AG AI AW BB BL BQ BS CU CW DM DO GD GP HT JM KN KY LC MF MQ MS PR SX TC TT VC VG VI" + - + territory: "029" + contains: "AN" + status: "deprecated" + - + territory: "003" + contains: "021 013 029" + grouping: "true" + - + territory: "030" + contains: "CN HK JP KP KR MN MO TW" + - + territory: "035" + contains: "BN ID KH LA MM MY PH SG TH TL VN" + - + territory: "035" + contains: "BU TP" + status: "deprecated" + - + territory: "039" + contains: "AD AL BA ES GI GR HR IT ME MK MT RS PT SI SM VA XK" + - + territory: "039" + contains: "CS YU" + status: "deprecated" + - + territory: "419" + contains: "013 029 005" + grouping: "true" + - + territory: "005" + contains: "AR BO BR CL CO EC FK GF GY PE PY SR UY VE" + - + territory: "053" + contains: "AU NF NZ" + - + territory: "054" + contains: "FJ NC PG SB VU" + - + territory: "057" + contains: "FM GU KI MH MP NR PW" + - + territory: "061" + contains: "AS CK NU PF PN TK TO TV WF WS" + - + territory: "034" + contains: "AF BD BT IN IR LK MV NP PK" + - + territory: "009" + contains: "053 054 057 061 QO" + - + territory: "QO" + contains: "AQ BV CC CX GS HM IO TF UM AC CP DG TA" + - + territory: "EU" + contains: "AT BE CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU LV MT NL PL PT SE SI SK BG RO" + grouping: "true" diff --git a/iso_data/territories/territoryContainment.json b/iso_data/territories/territoryContainment.json deleted file mode 100644 index 5ed0565f..00000000 --- a/iso_data/territories/territoryContainment.json +++ /dev/null @@ -1,180 +0,0 @@ -{ - "territoryContainment": [ - { - "territory": "001", - "contains": "019 002 150 142 009" - }, - { - "territory": "011", - "contains": "BF BJ CI CV GH GM GN GW LR ML MR NE NG SH SL SN TG" - }, - { - "territory": "013", - "contains": "BZ CR GT HN MX NI PA SV" - }, - { - "territory": "014", - "contains": "BI DJ ER ET KE KM MG MU MW MZ RE RW SC SO TZ UG YT ZM ZW" - }, - { - "territory": "142", - "contains": "145 143 030 034 035" - }, - { - "territory": "143", - "contains": "TM TJ KG KZ UZ" - }, - { - "territory": "145", - "contains": "AE AM AZ BH CY GE IL IQ JO KW LB OM PS QA SA SY TR YE" - }, - { - "territory": "145", - "contains": "NT YD", - "status": "deprecated" - }, - { - "territory": "015", - "contains": "DZ EG EH LY MA SD SS TN EA IC" - }, - { - "territory": "150", - "contains": "154 155 151 039" - }, - { - "territory": "150", - "contains": "EU", - "status": "grouping" - }, - { - "territory": "150", - "contains": "QU", - "status": "deprecated" - }, - { - "territory": "151", - "contains": "BG BY CZ HU MD PL RO RU SK UA" - }, - { - "territory": "154", - "contains": "GG IM JE AX DK EE FI FO GB IE IS LT LV NO SE SJ" - }, - { - "territory": "155", - "contains": "AT BE CH DE FR LI LU MC NL" - }, - { - "territory": "155", - "contains": "DD FX", - "status": "deprecated" - }, - { - "territory": "017", - "contains": "AO CD CF CG CM GA GQ ST TD" - }, - { - "territory": "017", - "contains": "ZR", - "status": "deprecated" - }, - { - "territory": "018", - "contains": "BW LS NA SZ ZA" - }, - { - "territory": "019", - "contains": "021 013 029 005" - }, - { - "territory": "019", - "contains": "003 419", - "status": "grouping" - }, - { - "territory": "002", - "contains": "015 011 017 014 018" - }, - { - "territory": "021", - "contains": "BM CA GL PM US" - }, - { - "territory": "029", - "contains": "AG AI AW BB BL BQ BS CU CW DM DO GD GP HT JM KN KY LC MF MQ MS PR SX TC TT VC VG VI" - }, - { - "territory": "029", - "contains": "AN", - "status": "deprecated" - }, - { - "territory": "003", - "contains": "021 013 029", - "grouping": "true" - }, - { - "territory": "030", - "contains": "CN HK JP KP KR MN MO TW" - }, - { - "territory": "035", - "contains": "BN ID KH LA MM MY PH SG TH TL VN" - }, - { - "territory": "035", - "contains": "BU TP", - "status": "deprecated" - }, - { - "territory": "039", - "contains": "AD AL BA ES GI GR HR IT ME MK MT RS PT SI SM VA XK" - }, - { - "territory": "039", - "contains": "CS YU", - "status": "deprecated" - }, - { - "territory": "419", - "contains": "013 029 005", - "grouping": "true" - }, - { - "territory": "005", - "contains": "AR BO BR CL CO EC FK GF GY PE PY SR UY VE" - }, - { - "territory": "053", - "contains": "AU NF NZ" - }, - { - "territory": "054", - "contains": "FJ NC PG SB VU" - }, - { - "territory": "057", - "contains": "FM GU KI MH MP NR PW" - }, - { - "territory": "061", - "contains": "AS CK NU PF PN TK TO TV WF WS" - }, - { - "territory": "034", - "contains": "AF BD BT IN IR LK MV NP PK" - }, - { - "territory": "009", - "contains": "053 054 057 061 QO" - }, - { - "territory": "QO", - "contains": "AQ BV CC CX GS HM IO TF UM AC CP DG TA" - }, - { - "territory": "EU", - "contains": "AT BE CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU LV MT NL PL PT SE SI SK BG RO", - "grouping": "true" - } - ] -} \ No newline at end of file diff --git a/lib/carmen.rb b/lib/carmen.rb index 961e36bc..4ef0bf33 100644 --- a/lib/carmen.rb +++ b/lib/carmen.rb @@ -45,7 +45,7 @@ def territories_path=(path) end def territories_path - @territories_path || (Carmen.root_path + 'iso_data/territories/territoryContainment.json') + @territories_path || (Carmen.root_path + 'iso_data/territories/territories.yml') end # Public: set an object to use as the I18n backend. diff --git a/lib/carmen/continent.rb b/lib/carmen/continent.rb index 76ab08c2..a5b69571 100644 --- a/lib/carmen/continent.rb +++ b/lib/carmen/continent.rb @@ -1,4 +1,4 @@ -require 'json' +require 'yaml' require 'carmen/country' module Carmen @@ -9,7 +9,7 @@ class Continent def initialize(data={}, parent=nil) @code = data['territory'] - @contains = data['contains'].split(' ') + @contains = data['contains'] @parent = parent end @@ -44,7 +44,11 @@ def world? private def contained_continents_or_countries - @contains.map { |c| code_to_object(c) } + if @contains.present? + @contains.map { |c| code_to_object(c) } + else + [] + end end def code_to_object(code) @@ -56,11 +60,11 @@ def code_to_object(code) end def self.continents - @continents ||= load_territory_containment.map { |tc| Continent.new(tc) } + @continents ||= load_territory_containment["territoryContainment"].map { |tc| Continent.new(tc) } end def self.load_territory_containment - JSON.parse(File.read(Carmen.territories_path))["territoryContainment"] + YAML.load_file(Carmen.territories_path) end end diff --git a/spec/carmen/continent_spec.rb b/spec/carmen/continent_spec.rb index 04b8a3fa..e4cd3f29 100644 --- a/spec/carmen/continent_spec.rb +++ b/spec/carmen/continent_spec.rb @@ -5,7 +5,7 @@ describe "#initialize when given a string of contained-country-codes" do it "will interpret them as carmen-countries and set them as contained_continents_or_countries" do - continent = Carmen::Continent.new({'territory' => '001', 'contains' => '002 003 004'}) + continent = Carmen::Continent.new({'territory' => '001', 'contains' => ['002', '003', '004']}) continent.sub_continents.count.must_equal 3 continent.sub_continents[0].class.must_equal Carmen::Continent @@ -16,7 +16,7 @@ describe "#initialize when given a string of contained-continent-codes" do it "will interpret them as carmen-continents and set them as contained_continents_or_countries" do - continent = Carmen::Continent.new({'territory' => '011', 'contains' => 'OC EU'}) + continent = Carmen::Continent.new({'territory' => '011', 'contains' => ['OC','EU']}) continent.countries.count.must_equal 2 continent.countries[0].class.must_equal Carmen::Country diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b41adece..78493873 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ require 'minitest/unit' require 'minitest/spec' require 'minitest/autorun' +require 'pry-byebug' require 'bundler/setup' require 'carmen' @@ -8,7 +9,7 @@ def setup_carmen_test_data_path Carmen.clear_data_paths Carmen.append_data_path(carmen_spec_data_path) - Carmen.territories_path = Carmen.root_path + 'spec_data/territories/territoryContainment.json' + Carmen.territories_path = Carmen.root_path + 'spec_data/territories/territories.yml' end def setup_carmen_test_i18n_backend diff --git a/spec_data/territories/territories.yml b/spec_data/territories/territories.yml new file mode 100644 index 00000000..4f46b1e4 --- /dev/null +++ b/spec_data/territories/territories.yml @@ -0,0 +1,29 @@ +--- + territoryContainment: + - + territory: "001" + contains: + - "002" + - "003" + - + territory: "002" + contains: + - "004" + - "005" + - + territory: "003" + contains: + - "006" + - "007" + - + territory: "004" + contains: + - "OC" + - "EU" + - "ES" + - + territory: "006" + contains: + - + territory: "007" + contains: diff --git a/spec_data/territories/territoryContainment.json b/spec_data/territories/territoryContainment.json deleted file mode 100644 index 8f7088e5..00000000 --- a/spec_data/territories/territoryContainment.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "territoryContainment": [ - { - "territory": "001", - "contains": "002 003" - }, - { - "territory": "002", - "contains": "004 005" - }, - { - "territory": "003", - "contains": "006 007" - }, - { - "territory": "004", - "contains": "OC EU ES" - }, - { - "territory": "006", - "contains": "" - }, - { - "territory": "007", - "contains": "" - } - ] -} \ No newline at end of file From 15302c46023b52290841785e115a2c27b2b1ce31 Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Fri, 29 May 2015 14:21:27 +0200 Subject: [PATCH 08/13] remove world-representation from continent-list --- lib/carmen/continent.rb | 11 ++++++----- lib/carmen/world.rb | 4 ++-- spec/carmen/continent_spec.rb | 10 +++++----- spec_data/territories/territories.yml | 3 +++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/carmen/continent.rb b/lib/carmen/continent.rb index a5b69571..82dea8e7 100644 --- a/lib/carmen/continent.rb +++ b/lib/carmen/continent.rb @@ -3,14 +3,11 @@ module Carmen class Continent - attr_reader :code - attr_reader :parent - def initialize(data={}, parent=nil) + def initialize(data={}) @code = data['territory'] @contains = data['contains'] - @parent = parent end def name @@ -34,7 +31,11 @@ def self.coded(code) end def self.all - continents + continents.reject { |c| c.world? } + end + + def self.world + continents.select { |c| c.world? }.first end def world? diff --git a/lib/carmen/world.rb b/lib/carmen/world.rb index b73bdd48..0c3cf33f 100644 --- a/lib/carmen/world.rb +++ b/lib/carmen/world.rb @@ -17,11 +17,11 @@ def subregion_class end def continents - Continent.all.detect { |c| c.world? }.sub_continents + Continent.world.sub_continents end def countries - Continent.all.detect { |c| c.world? }.countries + Continent.world.countries end def path diff --git a/spec/carmen/continent_spec.rb b/spec/carmen/continent_spec.rb index e4cd3f29..ad98fc53 100644 --- a/spec/carmen/continent_spec.rb +++ b/spec/carmen/continent_spec.rb @@ -47,9 +47,9 @@ describe '#sub_continents' do it 'returns the sub_continents of the given continent' do - Carmen::Continent.coded('001').sub_continents.count.must_equal 2 - Carmen::Continent.coded('001').sub_continents[0].code.must_equal "002" - Carmen::Continent.coded('001').sub_continents[1].code.must_equal "003" + Carmen::Continent.coded('002').sub_continents.count.must_equal 2 + Carmen::Continent.coded('002').sub_continents[0].code.must_equal "004" + Carmen::Continent.coded('002').sub_continents[1].code.must_equal "005" end end @@ -59,12 +59,12 @@ end it 'finds all countries of all sub_continents if some are present' do - Carmen::Continent.coded('001').countries.count.must_equal 3 + Carmen::Continent.coded('002').countries.count.must_equal 3 end end describe '#all' do - it 'returns all existing continents of all hierachies' do + it 'returns all existing continents of all hierachies without world' do Carmen::Continent.all.count.must_equal 6 end end diff --git a/spec_data/territories/territories.yml b/spec_data/territories/territories.yml index 4f46b1e4..6417a00c 100644 --- a/spec_data/territories/territories.yml +++ b/spec_data/territories/territories.yml @@ -21,6 +21,9 @@ - "OC" - "EU" - "ES" + - + territory: "005" + contains: - territory: "006" contains: From 5f3849d6332ec600c5cb5fa05e2c6b48e49249a1 Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Fri, 29 May 2015 14:30:36 +0200 Subject: [PATCH 09/13] remove debug-gems --- carmen.gemspec | 1 - spec/spec_helper.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/carmen.gemspec b/carmen.gemspec index 752fdd01..892323e7 100644 --- a/carmen.gemspec +++ b/carmen.gemspec @@ -19,6 +19,5 @@ Gem::Specification.new do |s| s.add_development_dependency('minitest', ["= 2.6.1"]) s.add_development_dependency('rake', '0.9.2.2') s.add_development_dependency('i18n') - s.add_development_dependency 'pry-byebug' s.add_dependency('activesupport', '>= 3.0.0') end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 78493873..636e68bb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,6 @@ require 'minitest/unit' require 'minitest/spec' require 'minitest/autorun' -require 'pry-byebug' require 'bundler/setup' require 'carmen' From 130a256339ff3b2c4babd5d406ba10e72ea4f069 Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Wed, 3 Jun 2015 11:11:39 +0200 Subject: [PATCH 10/13] Added a way to know a continents parent --- lib/carmen/continent.rb | 4 ++++ spec/carmen/continent_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/carmen/continent.rb b/lib/carmen/continent.rb index 82dea8e7..03a026bc 100644 --- a/lib/carmen/continent.rb +++ b/lib/carmen/continent.rb @@ -26,6 +26,10 @@ def countries end end + def continent + Carmen::Continent.all.detect { |c| c.sub_continents.include?(self) } + end + def self.coded(code) Continent.all.detect { |c| c.code == code } end diff --git a/spec/carmen/continent_spec.rb b/spec/carmen/continent_spec.rb index ad98fc53..1beadf07 100644 --- a/spec/carmen/continent_spec.rb +++ b/spec/carmen/continent_spec.rb @@ -63,6 +63,12 @@ end end + describe '#continent' do + it 'returns the parent-continent for this continent' do + Carmen::Continent.coded('004').continent.code.must_equal '002' + end + end + describe '#all' do it 'returns all existing continents of all hierachies without world' do Carmen::Continent.all.count.must_equal 6 From ee44a0a883a196b4709cc19f4b13b2daabec549f Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Wed, 3 Jun 2015 11:17:03 +0200 Subject: [PATCH 11/13] fixed territories location --- lib/carmen.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carmen.rb b/lib/carmen.rb index 4ef0bf33..e177ec9c 100644 --- a/lib/carmen.rb +++ b/lib/carmen.rb @@ -45,7 +45,7 @@ def territories_path=(path) end def territories_path - @territories_path || (Carmen.root_path + 'iso_data/territories/territories.yml') + @territories_path || (Carmen.root_path + 'iso_data/base/territories.yml') end # Public: set an object to use as the I18n backend. From 2dedfb0e8a9ad762bb8ffcea1186a65374cd70a2 Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Wed, 3 Jun 2015 11:41:38 +0200 Subject: [PATCH 12/13] fixed source YAML --- iso_data/base/territories.yml | 396 ++++++++++++++++++++++++++++++---- 1 file changed, 352 insertions(+), 44 deletions(-) diff --git a/iso_data/base/territories.yml b/iso_data/base/territories.yml index 4dc08e76..4f536f25 100644 --- a/iso_data/base/territories.yml +++ b/iso_data/base/territories.yml @@ -16,133 +16,441 @@ - "CI" - "CV" - "GH" - - "GM" GN GW LR ML MR NE NG SH SL SN TG" + - "GM" + - "GN" + - "GW" + - "LR" + - "ML" + - "MR" + - "NE" + - "NG" + - "SH" + - "SL" + - "SN" + - "TG" - territory: "013" - contains: "BZ CR GT HN MX NI PA SV" + contains: + - "BZ" + - "CR" + - "GT" + - "HN" + - "MX" + - "NI" + - "PA" + - "SV" - territory: "014" - contains: "BI DJ ER ET KE KM MG MU MW MZ RE RW SC SO TZ UG YT ZM ZW" + contains: + - "BI" + - "DJ" + - "ER" + - "ET" + - "KE" + - "KM" + - "MG" + - "MU" + - "MW" + - "MZ" + - "RE" + - "RW" + - "SC" + - "SO" + - "TZ" + - "UG" + - "YT" + - "ZM" + - "ZW" - territory: "142" - contains: "145 143 030 034 035" + contains: + - "145" + - "143" + - "030" + - "034" + - "035" - territory: "143" - contains: "TM TJ KG KZ UZ" + contains: + - "TM" + - "TJ" + - "KG" + - "KZ" + - "UZ" - territory: "145" - contains: "AE AM AZ BH CY GE IL IQ JO KW LB OM PS QA SA SY TR YE" + contains: + - "AE" + - "AM" + - "AZ" + - "BH" + - "CY" + - "GE" + - "IL" + - "IQ" + - "JO" + - "KW" + - "LB" + - "OM" + - "PS" + - "QA" + - "SA" + - "SY" + - "TR" + - "YE" - territory: "145" - contains: "NT YD" + contains: + - "NT" + - "YD" status: "deprecated" - territory: "015" - contains: "DZ EG EH LY MA SD SS TN EA IC" + contains: + - "DZ" + - "EG" + - "EH" + - "LY" + - "MA" + - "SD" + - "SS" + - "TN" + - "EA" + - "IC" - territory: "150" - contains: "154 155 151 039" - - - territory: "150" - contains: "EU" - status: "grouping" - - - territory: "150" - contains: "QU" - status: "deprecated" + contains: + - "154" + - "155" + - "151" + - "039" - territory: "151" - contains: "BG BY CZ HU MD PL RO RU SK UA" + contains: + - "BG" + - "BY" + - "CZ" + - "HU" + - "MD" + - "PL" + - "RO" + - "RU" + - "SK" + - "UA" - territory: "154" - contains: "GG IM JE AX DK EE FI FO GB IE IS LT LV NO SE SJ" + contains: + - "GG" + - "IM" + - "JE" + - "AX" + - "DK" + - "EE" + - "FI" + - "FO" + - "GB" + - "IE" + - "IS" + - "LT" + - "LV" + - "NO" + - "SE" + - "SJ" - territory: "155" - contains: "AT BE CH DE FR LI LU MC NL" + contains: + - "AT" + - "BE" + - "CH" + - "DE" + - "FR" + - "LI" + - "LU" + - "MC" + - "NL" - territory: "155" contains: "DD FX" status: "deprecated" - territory: "017" - contains: "AO CD CF CG CM GA GQ ST TD" + contains: + - "AO" + - "CD" + - "CF" + - "CG" + - "CM" + - "GA" + - "GQ" + - "ST" + - "TD" - territory: "017" contains: "ZR" status: "deprecated" - territory: "018" - contains: "BW LS NA SZ ZA" + contains: + - "BW" + - "LS" + - "NA" + - "SZ" + - "ZA" - territory: "019" - contains: "021 013 029 005" + contains: + - "021" + - "013" + - "029" + - "005" - territory: "019" - contains: "003 419" + contains: + - "003" + - "419" status: "grouping" - territory: "002" - contains: "015 011 017 014 018" + contains: + - "015" + - "011" + - "017" + - "014" + - "018" - territory: "021" - contains: "BM CA GL PM US" + contains: + - "BM" + - "CA" + - "GL" + - "PM" + - "US" - territory: "029" - contains: "AG AI AW BB BL BQ BS CU CW DM DO GD GP HT JM KN KY LC MF MQ MS PR SX TC TT VC VG VI" + contains: + - "AG" + - "AI" + - "AW" + - "BB" + - "BL" + - "BQ" + - "BS" + - "CU" + - "CW" + - "DM" + - "DO" + - "GD" + - "GP" + - "HT" + - "JM" + - "KN" + - "KY" + - "LC" + - "MF" + - "MQ" + - "MS" + - "PR" + - "SX" + - "TC" + - "TT" + - "VC" + - "VG" + - "VI" - territory: "029" - contains: "AN" + contains: + - "AN" status: "deprecated" - territory: "003" - contains: "021 013 029" + contains: + - "021" + - "013" + - "029" grouping: "true" - territory: "030" - contains: "CN HK JP KP KR MN MO TW" + contains: + - "CN" + - "HK" + - "JP" + - "KP" + - "KR" + - "MN" + - "MO" + - "TW" - territory: "035" - contains: "BN ID KH LA MM MY PH SG TH TL VN" + contains: + - "BN" + - "ID" + - "KH" + - "LA" + - "MM" + - "MY" + - "PH" + - "SG" + - "TH" + - "TL" + - "VN" - territory: "035" - contains: "BU TP" + contains: + - "BU" + - "TP" status: "deprecated" - territory: "039" - contains: "AD AL BA ES GI GR HR IT ME MK MT RS PT SI SM VA XK" + contains: + - "AD" + - "AL" + - "BA" + - "ES" + - "GI" + - "GR" + - "HR" + - "IT" + - "ME" + - "MK" + - "MT" + - "RS" + - "PT" + - "SI" + - "SM" + - "VA" + - "XK" - territory: "039" - contains: "CS YU" + contains: + - "CS" + - "YU" status: "deprecated" - territory: "419" - contains: "013 029 005" + contains: + - "013" + - "029" + - "005" grouping: "true" - territory: "005" - contains: "AR BO BR CL CO EC FK GF GY PE PY SR UY VE" + contains: + - "AR" + - "BO" + - "BR" + - "CL" + - "CO" + - "EC" + - "FK" + - "GF" + - "GY" + - "PE" + - "PY" + - "SR" + - "UY" + - "VE" - territory: "053" - contains: "AU NF NZ" + contains: + - "AU" + - "NF" + - "NZ" - territory: "054" - contains: "FJ NC PG SB VU" + contains: + - "FJ" + - "NC" + - "PG" + - "SB" + - "VU" - territory: "057" - contains: "FM GU KI MH MP NR PW" + contains: + - "FM" + - "GU" + - "KI" + - "MH" + - "MP" + - "NR" + - "PW" - territory: "061" - contains: "AS CK NU PF PN TK TO TV WF WS" + contains: + - "AS" + - "CK" + - "NU" + - "PF" + - "PN" + - "TK" + - "TO" + - "TV" + - "WF" + - "WS" - territory: "034" - contains: "AF BD BT IN IR LK MV NP PK" + contains: + - "AF" + - "BD" + - "BT" + - "IN" + - "IR" + - "LK" + - "MV" + - "NP" + - "PK" - territory: "009" - contains: "053 054 057 061 QO" + contains: + - "053" + - "054" + - "057" + - "061" + - "QO" - territory: "QO" - contains: "AQ BV CC CX GS HM IO TF UM AC CP DG TA" + contains: + - "AQ" + - "BV" + - "CC" + - "CX" + - "GS" + - "HM" + - "IO" + - "TF" + - "UM" + - "AC" + - "CP" + - "DG" + - "TA" - territory: "EU" - contains: "AT BE CY CZ DE DK EE ES FI FR GB GR HR HU IE IT LT LU LV MT NL PL PT SE SI SK BG RO" + contains: + - "AT" + - "BE" + - "CY" + - "CZ" + - "DE" + - "DK" + - "EE" + - "ES" + - "FI" + - "FR" + - "GB" + - "GR" + - "HR" + - "HU" + - "IE" + - "IT" + - "LT" + - "LU" + - "LV" + - "MT" + - "NL" + - "PL" + - "PT" + - "SE" + - "SI" + - "SK" + - "BG" + - "RO" grouping: "true" From eb2d52b5c842e2d0e22d7f7830120312fc625932 Mon Sep 17 00:00:00 2001 From: Tim Adler Date: Wed, 3 Jun 2015 11:45:33 +0200 Subject: [PATCH 13/13] still one entry broken --- iso_data/base/territories.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iso_data/base/territories.yml b/iso_data/base/territories.yml index 4f536f25..b5547c56 100644 --- a/iso_data/base/territories.yml +++ b/iso_data/base/territories.yml @@ -170,7 +170,9 @@ - "NL" - territory: "155" - contains: "DD FX" + contains: + - "DD" + - "FX" status: "deprecated" - territory: "017" @@ -186,7 +188,8 @@ - "TD" - territory: "017" - contains: "ZR" + contains: + - "ZR" status: "deprecated" - territory: "018"