everypolitician / viewer-sinatra

Sinatra app for (pre)viewing EveryPolitician website dynamically
http://everypolitician.org/
5 stars 5 forks source link

Extend EveryPolitician Index with a legislature method #15316

Open octopusinvitro opened 8 years ago

octopusinvitro commented 8 years ago

Problem

At the moment, to pass a house to a Page constructor, we have to do a bit of a dance like this:

  subject do
    country = index_at_known_sha.country('united-states-of-america')
    house   = country.legislature('senate')
    Page::HouseDownload.new(
      house: house,
      index: index_at_known_sha
    )
  end

This adds a bit of complexity and raises the flog score a bit.

Proposed Solution

It would be nice if we could add a method to the lib/everypolitician_extensions.rb to extend the Everypolitician::Index with a method that allows you to pass a country and a house slug.

module IndexExtension
  def legislature(country_slug, legislature_slug)
    # ...
  end
end

So that you can do

    Page::HouseDownload.new(
      house: index_at_known_sha.legislature('united-states-of-america', 'senate'),
      index: index_at_known_sha
    )

Acceptance Criteria

house = index_at_known_sha.legislature('united-states-of-america', 'senate')
house.country.name 
# United States of America
house.name
# Senate
tmtmtmtm commented 8 years ago

:+1:

Would the method work if it were just called legislature? country_legislature is a bit of a mouthful.