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

_enabled: false on subregions only works half the time? #50

Open
kinman-enphase opened this issue Nov 4, 2014 · 1 comment
Open

_enabled: false on subregions only works half the time? #50

kinman-enphase opened this issue Nov 4, 2014 · 1 comment

Comments

@kinman-enphase
Copy link

For several countries, I'd like to suppress all subregions. I set the _enabled attribute to false on all subregions, but only every other one is actually suppressed. For example:

bd.yml


---
- code: '1'
  _enabled: false
- code: '2'
  _enabled: false
- code: '3'
  _enabled: false
- code: '4'
  _enabled: false
- code: '5'
  _enabled: false
- code: '6'
  _enabled: false

Rails console:

> Carmen::Country.coded("BD").subregions.map &:code
["2", "4", "6"]

Is there better way to suppress all subregions?

@kinman-enphase
Copy link
Author

The problem appears to be in Carmen::Region#flatten_data:

flattened.each do |hash|
  flattened.delete(hash) if hash['_enabled'] == false
end

It would be better to create a new collection rather than to mutate the one being iterated over:

Ruby console

> enabled_regions = flattened.select {|r| r['_enabled']}
[]

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

No branches or pull requests

1 participant