Skip to content

Commit

Permalink
fixup! Extract MemberPage
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Denman committed May 2, 2017
1 parent 02b385c commit c859362
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/member_page.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'scraped'
require 'pry'

# This class represents the profile page of a given member
class MemberPage < Scraped::HTML
Expand All @@ -24,23 +23,20 @@ class MemberPage < Scraped::HTML
end

field :honorific_suffix do
name_parts[1..-1].map(&:tidy).join(', ')
name_parts.drop(1).map(&:tidy).join(', ')
end

field :gender do
return 'female' if honorific_prefix.include?('Mrs')
end

field :faction do
f = bio.xpath('//p[contains(.,"Political affiliation")]/'\
'following-sibling::ul[not(position() > 1)]/li/text()')
return 'Independent' if f.empty?

return 'Independent' if (affiliation = political_affiliation).empty?
# Some member pages list more than one group affiliation for that member
# Here, we remove affiliations with known non-party groups
f.map(&:to_s).map(&:tidy).find do |party|
!non_party_groups.to_s.include? party
end
affiliation.map(&:to_s).map(&:tidy).reject do |party|
non_party_groups.to_s.include? party
end.first
end

field :email do
Expand Down Expand Up @@ -69,8 +65,7 @@ class MemberPage < Scraped::HTML
end

field :area do
# splitting here by en-dash (not hyphen)
area_parts.last.split('–').last.tidy
area_parts.last.split("\u{2013}").last.tidy
end

field :area_type do
Expand All @@ -91,7 +86,7 @@ def area_parts
end

def name_parts
bio.css('h2').text.split(',')
bio.css('h2').text.split(',').map(&:tidy)
end

def titles
Expand All @@ -103,10 +98,15 @@ def bio
end

def non_party_groups
[
Set[
'Kowloon West New Dynamic',
'New Territories Association of Societies',
'April Fifth Action',
]
end

def political_affiliation
bio.xpath('//p[contains(.,"Political affiliation")]/'\
'following-sibling::ul[not(position() > 1)]/li/text()')
end
end

0 comments on commit c859362

Please sign in to comment.