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

attribute based finder methods, override selected html option, fix for loading yaml. #11

Merged
merged 6 commits into from
Dec 6, 2011
Merged

attribute based finder methods, override selected html option, fix for loading yaml. #11

merged 6 commits into from
Dec 6, 2011

Conversation

esfourteen-zz
Copy link
Contributor

I modified the Country class and overrode method_missing to add the following functionality:

find_by_attr(val)
find_country_by_attr(val)
find_all_by_attr(val)
find_all_countries_by_attr(val)
  • find_by and find_all_by return the original hash or array of hash's from the Data hash
  • find_country_by and find_all_countries_by returns a Country object or an array of Country objects

This mimics the original functionality you had for find_by_name and find_country_by_name.

A few examples:

Country.find_by_name('us') # returns Hash for country 'US'
Country.find_country_by_name('us') # returns Country object for 'US'
Country.find_by_alpha3('usa') # returns Hash for country 'US'
Country.find_all_countries_by_region('Americas') # returns array of Country objects where region => 'Americas'

I did not modify any tests yet as I couldn't get them to run, but I can fix that if you are interested in pulling in these changes.

Also in this commit is a fix for how yaml was being loaded, YAML is actually defined without including the yaml class, at least in 1.9.3, but with limited functionality, so the check for defined?(YAML) was insufficient.

And finally, I modified the country_select helper to allow overriding the selected html option.

@hexorx
Copy link
Collaborator

hexorx commented Nov 28, 2011

These are some nice improvements! I will merge them in if all current tests pass. Any additional tests and read me updates would also be appreciated :-)

@esfourteen-zz
Copy link
Contributor Author

I am glad you find them useful as well, don't merge yet and I will make sure tests pass and add additional testing and some changes to README.

@hexorx
Copy link
Collaborator

hexorx commented Nov 28, 2011

Perfect.

@esfourteen-zz
Copy link
Contributor Author

Take a look and please let me know if anything is unclear or should be addressed/fixed.

hexorx added a commit that referenced this pull request Dec 6, 2011
attribute based finder methods, override selected html option, fix for loading yaml.
@hexorx hexorx merged commit 711625f into countries:master Dec 6, 2011
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

Successfully merging this pull request may close these issues.

3 participants