Skip to content

Commit

Permalink
Merge 8738c61 into 15c697b
Browse files Browse the repository at this point in the history
  • Loading branch information
giusepped committed Feb 8, 2017
2 parents 15c697b + 8738c61 commit f47c93d
Show file tree
Hide file tree
Showing 119 changed files with 10,137 additions and 116 deletions.
5 changes: 3 additions & 2 deletions lib/parliament.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
require 'parliament/version'
require 'parliament/request'
require 'parliament/response'
require 'parliament/decorators/person'
require 'parliament/decorators/sitting'

# require all the decorators
Dir[File.join(File.dirname(__FILE__), 'parliament/decorators', '*.rb')].each { |decorator| require decorator }

module Parliament
# Your code goes here...
Expand Down
17 changes: 17 additions & 0 deletions lib/parliament/decorators/constituency_area.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Parliament
module Decorators
module ConstituencyArea
def latitude
respond_to?(:constituencyAreaLatitude) ? constituencyAreaLatitude : ''
end

def longitude
respond_to?(:constituencyAreaLongitude) ? constituencyAreaLongitude : ''
end

def polygon
respond_to?(:constituencyAreaExtent) ? constituencyAreaExtent : ''
end
end
end
end
58 changes: 58 additions & 0 deletions lib/parliament/decorators/constituency_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module Parliament
module Decorators
module ConstituencyGroup
def name
respond_to?(:constituencyGroupName) ? constituencyGroupName : ''
end

def start_date
respond_to?(:constituencyGroupStartDate) ? constituencyGroupStartDate : ''
end

def end_date
respond_to?(:constituencyGroupEndDate) ? constituencyGroupEndDate : ''
end

def seats
respond_to?(:constituencyGroupHasHouseSeat) ? constituencyGroupHasHouseSeat : []
end

def seat_incumbencies
return @seat_incumbencies unless @seat_incumbencies.nil?

seat_incumbencies = []
seats.each do |seat|
seat_incumbencies << seat.seat_incumbencies
end

@seat_incumbencies = seat_incumbencies.flatten.uniq
end

def members
return @members unless @members .nil?

members = []
seat_incumbencies.each do |seat_incumbency|
members << seat_incumbency.member
end

@members = members.flatten.uniq
end

def area
respond_to?(:constituencyGroupHasConstituencyArea) ? constituencyGroupHasConstituencyArea.first : nil
end

def contact_points
return @contact_points unless @contact_points.nil?

contact_points = []
seat_incumbencies.each do |seat_incumbency|
contact_points << seat_incumbency.contact_points
end

@contact_points = contact_points.flatten.uniq
end
end
end
end
9 changes: 9 additions & 0 deletions lib/parliament/decorators/contact_point.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Parliament
module Decorators
module ContactPoint
def postal_addresses
respond_to?(:contactPointHasPostalAddress) ? contactPointHasPostalAddress : []
end
end
end
end
9 changes: 9 additions & 0 deletions lib/parliament/decorators/gender.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Parliament
module Decorators
module Gender
def name
respond_to?(:genderName) ? genderName : ''
end
end
end
end
9 changes: 9 additions & 0 deletions lib/parliament/decorators/gender_identity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Parliament
module Decorators
module GenderIdentity
def gender
respond_to?(:genderIdentityHasGender) ? genderIdentityHasGender.first : nil
end
end
end
end
9 changes: 9 additions & 0 deletions lib/parliament/decorators/house.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Parliament
module Decorators
module House
def name
respond_to?(:houseName) ? houseName : ''
end
end
end
end
17 changes: 17 additions & 0 deletions lib/parliament/decorators/house_seat.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Parliament
module Decorators
module HouseSeat
def house
respond_to?(:houseSeatHasHouse) ? houseSeatHasHouse.first : nil
end

def constituency
respond_to?(:houseSeatHasConstituencyGroup) ? houseSeatHasConstituencyGroup.first : nil
end

def seat_incumbencies
respond_to?(:houseSeatHasSeatIncumbency) ? houseSeatHasSeatIncumbency : []
end
end
end
end
17 changes: 17 additions & 0 deletions lib/parliament/decorators/party_membership.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Parliament
module Decorators
module PartyMembership
def party
respond_to?(:partyMembershipHasParty) ? partyMembershipHasParty.first : nil
end

def start_date
respond_to?(:partyMembershipStartDate) ? partyMembershipStartDate : ''
end

def end_date
respond_to?(:partyMembershipEndDate) ? partyMembershipEndDate : ''
end
end
end
end
85 changes: 82 additions & 3 deletions lib/parliament/decorators/person.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,91 @@
module Parliament
module Decorators
module Person
def given_name
respond_to?(:personGivenName) ? personGivenName : ''
end

def family_name
respond_to?(:personFamilyName) ? personFamilyName : ''
end

def other_name
respond_to?(:personOtherNames) ? personOtherNames : ''
end

def date_of_birth
respond_to?(:personDateOfBirth) ? personDateOfBirth : ''
end

def full_name
full_name = ''
full_name += respond_to?(:personGivenName) ? personGivenName + ' ' : ''
full_name += respond_to?(:personFamilyName) ? personFamilyName : ''
full_name.rstrip
end

def seat_incumbencies
respond_to?(:memberHasSeatIncumbency) ? memberHasSeatIncumbency : []
end

def seats
return @seats unless @seats.nil?

seats = []
seat_incumbencies.each do |seat_incumbency|
seats << seat_incumbency.seat
end

@seats = seats.flatten.uniq
end

def houses
respond_to?(:personHasSitting) ? personHasSitting.first.sittingHasHouse : []
return @houses unless @houses.nil?

houses = []
seats.each do |seat|
houses << seat.house
end

@houses = houses.flatten.uniq
end

def constituencies
return @constituencies unless @constituencies.nil?

constituencies = []
seats.each do |seat|
constituencies << seat.constituency
end

@constituencies = constituencies.flatten.uniq
end

def party_memberships
respond_to?(:partyMemberHasPartyMembership) ? partyMemberHasPartyMembership : []
end

def parties
return @parties unless @parties.nil?

parties = []
party_memberships.each do |party_membership|
parties << party_membership.party
end

@parties = parties.flatten.uniq.compact
end

def contact_points
respond_to?(:personHasContactPoint) ? personHasContactPoint : []
end

def gender_identities
respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : []
end

def sittings
respond_to?(:personHasSitting) ? personHasSitting : []
def gender
gender_identities.empty? ? nil : gender_identities.first.gender
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions lib/parliament/decorators/postal_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Parliament
module Decorators
module PostalAddress
def full_address
address_array.join(', ')
end

private

def address_array
address_array = []
(1..5).each do |i|
if respond_to?("addressLine#{i}".to_sym)
address_array << instance_variable_get("@addressLine#{i}".to_sym)
end
end
address_array << postCode if respond_to?(:postCode)
address_array
end
end
end
end
39 changes: 39 additions & 0 deletions lib/parliament/decorators/seat_incumbency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Parliament
module Decorators
module SeatIncumbency
def start_date
respond_to?(:seatIncumbencyStartDate) ? seatIncumbencyStartDate : ''
end

def end_date
respond_to?(:seatIncumbencyEndDate) ? seatIncumbencyEndDate : ''
end

def seat
respond_to?(:seatIncumbencyHasHouseSeat) ? seatIncumbencyHasHouseSeat.first : nil
end

def member
respond_to?(:seatIncumbencyHasMember) ? seatIncumbencyHasMember.first : nil
end

def current?
has_end_date = respond_to?(:seatIncumbencyEndDate)

!has_end_date
end

def house
seat.nil? ? nil : seat.house
end

def constituency
seat.nil? ? nil : seat.constituency
end

def contact_points
respond_to?(:seatIncumbencyHasContactPoint) ? seatIncumbencyHasContactPoint : []
end
end
end
end
9 changes: 0 additions & 9 deletions lib/parliament/decorators/sitting.rb

This file was deleted.

2 changes: 2 additions & 0 deletions parliament-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'simplecov', '~> 0.12.0'
spec.add_development_dependency 'vcr', '~> 3.0.3'
spec.add_development_dependency 'webmock', '~> 2.3.2'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'pry-nav'
end
18 changes: 11 additions & 7 deletions spec/fixtures/people_members_current.nt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<http://id.ukpds.org/cea89432-e046-4013-a9ba-e93d0468d186> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Person> .
<http://id.ukpds.org/cea89432-e046-4013-a9ba-e93d0468d186> <http://id.ukpds.org/schema/forename> "Person 1 - forename" .
<http://id.ukpds.org/cea89432-e046-4013-a9ba-e93d0468d186> <http://id.ukpds.org/schema/surname> "Person 1 - surname" .
<http://id.ukpds.org/cea89432-e046-4013-a9ba-e93d0468d186> <http://id.ukpds.org/schema/personGivenName> "Person 1 - personGivenName" .
<http://id.ukpds.org/cea89432-e046-4013-a9ba-e93d0468d186> <http://id.ukpds.org/schema/personFamilyName> "Person 1 - personFamilyName" .
<http://id.ukpds.org/HouseOfCommons> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/House> .
<http://id.ukpds.org/HouseOfCommons> <http://id.ukpds.org/schema/houseHasSitting> <http://id.ukpds.org/6569ce56-020e-4c43-a36e-ca5bf3e576b7> .
<http://id.ukpds.org/4ef6c7b7-a5c8-4dde-a5a5-29c9f80d8a27> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Constituency> .
Expand All @@ -18,10 +18,10 @@
<http://id.ukpds.org/b40f3248-3f53-4af5-8349-024db28d2636> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/PartyMembership> .
<http://id.ukpds.org/b40f3248-3f53-4af5-8349-024db28d2636> <http://id.ukpds.org/schema/partyMembershipStartDate> "2016-05-03"^^<http://www.w3.org/2001/XMLSchema#date> .
<http://id.ukpds.org/b40f3248-3f53-4af5-8349-024db28d2636> <http://id.ukpds.org/schema/partyMembershipHasParty> <http://id.ukpds.org/80234c90-f86a-4942-b6ae-d1e57a0b378d> .
<http://id.ukpds.org/b40f3248-3f53-4af5-8349-024db28d2636> <http://id.ukpds.org/schema/partyMembershipHasPerson> <http://id.ukpds.org/cea89432-e046-4013-a9ba-e93d0468d186> .
<http://id.ukpds.org/cea89432-e046-4013-a9ba-e93d0468d186> <http://id.ukpds.org/schema/partyMemberHasPartyMembership> <http://id.ukpds.org/b40f3248-3f53-4af5-8349-024db28d2636> .
<http://id.ukpds.org/0e67b03f-9d7a-4793-9902-60d977647494> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Person> .
<http://id.ukpds.org/0e67b03f-9d7a-4793-9902-60d977647494> <http://id.ukpds.org/schema/forename> "Person 2 - forename" .
<http://id.ukpds.org/0e67b03f-9d7a-4793-9902-60d977647494> <http://id.ukpds.org/schema/surname> "Person 2 - surname" .
<http://id.ukpds.org/0e67b03f-9d7a-4793-9902-60d977647494> <http://id.ukpds.org/schema/personGivenName> "Person 2 - personGivenName" .
<http://id.ukpds.org/0e67b03f-9d7a-4793-9902-60d977647494> <http://id.ukpds.org/schema/personFamilyName> "Person 2 - personFamilyName" .
<http://id.ukpds.org/HouseOfCommons> <http://id.ukpds.org/schema/houseHasSitting> <http://id.ukpds.org/e6561964-8c1e-41e7-8755-cc3a561fd8ed> .
<http://id.ukpds.org/c112ac5c-fe6a-4930-bcfe-92dd12d91c8f> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Constituency> .
<http://id.ukpds.org/c112ac5c-fe6a-4930-bcfe-92dd12d91c8f> <http://id.ukpds.org/schema/constituencyName> "Constituency 2 - name" .
Expand All @@ -37,5 +37,9 @@
<http://id.ukpds.org/fa0e1545-9158-4fd6-93a3-5d5af509c920> <http://id.ukpds.org/schema/partyMembershipHasParty> <http://id.ukpds.org/80234c90-f86a-4942-b6ae-d1e57a0b378d> .
<http://id.ukpds.org/fa0e1545-9158-4fd6-93a3-5d5af509c920> <http://id.ukpds.org/schema/partyMembershipHasPerson> <http://id.ukpds.org/0e67b03f-9d7a-4793-9902-60d977647494> .
<http://id.ukpds.org/68f804c8-c16b-4a77-8403-ae04d90e3a9d> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Person> .
<http://id.ukpds.org/68f804c8-c16b-4a77-8403-ae04d90e3a9d> <http://id.ukpds.org/schema/forename> "Person 3 - forename" .
<http://id.ukpds.org/68f804c8-c16b-4a77-8403-ae04d90e3a9d> <http://id.ukpds.org/schema/surname> "Person 3 - surname" .
<http://id.ukpds.org/68f804c8-c16b-4a77-8403-ae04d90e3a9d> <http://id.ukpds.org/schema/personFamilyName> "Person 3 - personFamilyName" .

<http://id.ukpds.org/68f804c8-c16b-4a77-8403-ae04d90e3abc> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Person> .
<http://id.ukpds.org/68f804c8-c16b-4a77-8403-ae04d90e3abc> <http://id.ukpds.org/schema/personGivenName> "Person 4 - personGivenName" .

<http://id.ukpds.org/68f804c8-c16b-4a77-8403-ae04d90e3123> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://id.ukpds.org/schema/Person> .
Loading

0 comments on commit f47c93d

Please sign in to comment.