From 198b5a9e3af545fe29eeb771017bfc76594f58ac Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Tue, 21 Feb 2017 11:03:39 +0100 Subject: [PATCH] README docs about using unstable position data We want to add an interface for interacting with unstable position data to viewer-sinatra. This interface is an extension to the `EveryPolitician::Legislature` class, which operates on the `unstable/positions.csv` file in a legislature's directory in everypolitician-data. --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 4956b85dd..86291e588 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,38 @@ bundle exec rake test:all bundle exec rake ``` +## Internal documentation + +### Interacting with unstable data + +We use data from the `unstable/positions.csv` file in a legislature's +directory to display cabinet memberships on the website. Because this data +is unstable there currently aren't methods in [the `everypolitician` +gem](https://github.com/everypolitician/everypolitician-ruby) for +interacting with it, so viewer-sinatra has some of its own classes for +dealing with it. These classes live in the +`lib/everypolitician_extensions.rb` file and are documented below. + +#### Get all cabinet memberships for a person + +To print all of the known cabinet memberships for a person, you can do the +following: + +```ruby +house_of_commons = Everypolitician::Index.new.country('UK').legislature('Commons') +person = house_of_commons.popolo.persons.find_by(name: 'Gordon Brown') + +person.cabinet_memberships.each do |membership| + puts "#{person.name} was #{membership.label} #{membership.start_date} - #{membership.end_date}" +end +``` + +Which will output something like this: + +``` +Gordon Brown was Prime Minister of the United Kingdom 2007-06-27 - 2010-05-11 +Gordon Brown was Chancellor of the Exchequer 1997-05-02 - 2007-06-27 +``` ## Sinatra, SASS, styling