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

Official support for being able to pass multiple key-value pairs to the find method #33

Open
octopusinvitro opened this issue Aug 4, 2016 · 0 comments

Comments

@octopusinvitro
Copy link
Contributor

octopusinvitro commented Aug 4, 2016

Based on this discussion, regarding officially supporting the possibility to pass multiple key-value pairs to the find method of countries and legislatures, do we want to offer the possibility of:

1. searching for a country or legislature by more than one field at the same time?, for example:

country = Everypolitician::Country.find(country: 'Abkhazia', code: 'GE-AB')

2. or would we only support searching by several fields but just one at a time? For example:

country = Everypolitician::Country.find(name: 'Australia')

3. or just by slug?

country = Everypolitician::Country.find('Australia') # Default behavior ATM

In cases 2. and 3., it would be nice to simplify the code to the behaviour we want. For example, if we only support 3., one possible simplification (for legislatures) could be:

    def legislature(query)
      query = { slug: query } if query.is_a?(String)
      legislature = legislatures.find do |l|
        query.all? { |k, v| l.__send__(k).to_s.downcase == v.to_s.downcase }
      end
      fail Error, "Unknown legislature: #{query}" if legislature.nil?
      legislature
    end

with:

    def legislature(query)
      legislature = legislatures.find do |l|
        l.__send__(:slug).to_s.downcase == query.to_s.downcase }
      end
      fail Error, "Unknown legislature: #{query}" if legislature.nil?
      legislature
    end

This would also be more in line with how we documented the code in the README, where we are telling people to pass the slug to the method.

tmtmtmtm added a commit that referenced this issue Aug 30, 2016
update README to indicate data is retrieved online, plus links
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