carmen
carmen copied to clipboard
Continent data
Would it make sense to include information about continents in Carmen?
Geonames has a nice database of countries with their corresponding continent code (parseable file). I ran a little script and it turns out all Carmen::Country.all.map(&:code)
are included.
These APIs would be useful:
europe = Carmen::Continent.coded('EU')
# <#Carmen::Continent name="Europe">
europe.countries # Alias: `europe.subregions`
# [<#Carmen::Country name="Andorra">, <#Carmen::Country name="Albania">, <#Carmen::Country name="Austria">, ...]
netherlands = Carmen::Country.coded('NL')
# <#Carmen::Country name="Netherlands">
netherlands.continent # Alias: `netherlands.parent`
# <#Carmen::Continent name="Europe">
I could work on this.
I spent a little time thinking about how to accomplish this a while back, but didn't start writing any code for it. The challenge is deciding if the current YAML file structure is extended an additional level, or if it is worth special-casing continents to avoid doing so.
I would be interested in what you were thinking, as this would be a nice addition to the library.
:+1: This would be useful.
Adding another YAML level is probably the best approach.
I am thinking of putting continent list and continent code in each of the country in world.yml Do you guys think it is a good idea
world.yml
---
- alpha_2_code: AU
alpha_3_code: AUS
numeric_code: "001"
continent_code: OC
type: country
- alpha_2_code: FO
alpha_3_code: FRO
numeric_code: "002"
continent_code: EU
type: country
- alpha_2_code: EE
alpha_3_code: EST
continent_code: EU
numeric_code: "003"
type: country
- continent_code: EU
type: continent
- continent_code: OC
type: continent
- continent_code: AS
type: continent
@emptyflask what do you mean by adding another YAML level?
:+1: I'm in a similar boat of either extending carmen's functionality to include this or rolling my own solution. Looks like this is kind of an old issue; would love to hear if any of you have pursued this further.
FWIW I'll give my 2c on previous comments. The complication behind extending the yaml structure to another level is that you would need to read multiple files to get a full list of countries (we don't need have this complication for subregions because we only ever care about a single country's subregions). My gut feeling is that @wizztjh's solution is simpler. Would we just have another yml alongside world.yml
with the continent data?
Just to feel out what an API would be like:
Carmen::Continent.all # => [<#Carmen::Continent name="North America">, ...]
na = Carmen::Continent.coded("NA")
na = Carmen::Continent.named("North America")
na.countries # => [<#Carmen::Country name="United States">, ...]
us = Carmen::Country.coded("US")
us.continent # => <#Carmen::Continent name="North America">
Missing anything?
By the way sorry for my lack of comments. I opened the issue saying I could work on this but truth is I didn’t end up having enough time. Feel free to get this started, anyone!
I think the API you suggest makes sense @joekur. With added aliases for na.countries
=> na.subregions
and us.continent
=> us.parent
.
I've dug into it a little more. Adding another layer would actually be more elegant because it would follow the tree structure that's already in place. Ideally the structure would be World > Continents > Countries
. But (and this is a big 'but') - this would break existing users' yaml overrides. For the same reason I'm also wary of changing Carmen::World
's functionality. I'd like to be elegant, but at the same time I'd like this to be merged, and bumping major versions is no small decision. Would love to hear from @jim
Adding another YAML layer for continents would probably be OK.
Breaking other user's YAML overrides is not a big deal as long as this was clearly stated in the docs and the version number is bumped accordingly. The implementations of Country.coded
et al would also need to be updated to somehow search through all countries and not just those belonging to a single continent.
I haven't had much time to work on this library recently, so thank you to everyone for working together to address this feature request!
After I added a continent to the spec_data, the overlay spec failed because the data type is fort
. Which been filtered out in Country.query_collection
I think all data in the Country.all should be country. I will change the spec_data of overlay data
- alpha_2_code: SE
alpha_3_code: SEA
numeric_code: "004"
common_name: Sealand
name: Sealand
official_name: The Principality of Sealand
type: fort
the commit dddc9d24c63fc77f10e530e6cd1e38cd3a0ec0a6
Any update on this @wizztjh? :)
Hi Dain, No progress from me. Occupied with something else. On Mar 13, 2015 3:10 AM, "Dain Miller" [email protected] wrote:
Any update on this @wizztjh https://github.com/wizztjh? :)
— Reply to this email directly or view it on GitHub https://github.com/jim/carmen/issues/133#issuecomment-78574442.
Thanks for the status @wizztjh. Will leave it open for the time being :)
I found https://github.com/beefsack/ruby-continent
It seems to match properly with every Carmen country
countries = Carmen::Country.all
countries.map {|c| Continent.by_alpha_2_code(c.code) || nil }.compact.size == countries.size
# true
It would be good if the above made it to the documentation. I didn't know you can Carmen::Country.all