Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continent data #133

Open
rafbm opened this issue Nov 25, 2013 · 15 comments
Open

Continent data #133

rafbm opened this issue Nov 25, 2013 · 15 comments
Labels

Comments

@rafbm
Copy link
Contributor

rafbm commented Nov 25, 2013

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.

@jim
Copy link
Collaborator

jim commented Mar 1, 2014

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.

@emptyflask
Copy link
Contributor

👍 This would be useful.

Adding another YAML level is probably the best approach.

@wizztjh
Copy link

wizztjh commented Sep 25, 2014

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

@wizztjh
Copy link

wizztjh commented Oct 20, 2014

@emptyflask what do you mean by adding another YAML level?

@joekur
Copy link

joekur commented Dec 1, 2014

👍 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.

@joekur
Copy link

joekur commented Dec 1, 2014

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?

@rafbm
Copy link
Contributor Author

rafbm commented Dec 2, 2014

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.

@joekur
Copy link

joekur commented Dec 2, 2014

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

@jim
Copy link
Collaborator

jim commented Dec 9, 2014

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!

@wizztjh
Copy link

wizztjh commented Jan 15, 2015

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 dddc9d2

@ghost
Copy link

ghost commented Mar 12, 2015

Any update on this @wizztjh? :)

@wizztjh
Copy link

wizztjh commented Mar 13, 2015

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
#133 (comment).

@ghost
Copy link

ghost commented Mar 13, 2015

Thanks for the status @wizztjh. Will leave it open for the time being :)

@ghost ghost added the feature label Apr 23, 2015
@j15e
Copy link
Contributor

j15e commented May 18, 2015

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

@kaka-ruto
Copy link

It would be good if the above made it to the documentation. I didn't know you can Carmen::Country.all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants