Skip to content

Commit

Permalink
WIP: Use decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Denman committed May 23, 2017
1 parent 22ac53d commit d153856
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/decrypt_email_addresses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'scraped'
require_relative 'decrypted_email'

class DecryptEmailAddresses < Scraped::Response::Decorator
def body
Nokogiri::HTML(super).tap do |doc|
doc.css('a span @data-cfemail').each do |email|
email.value = DecryptedEmail.new(encrypted_email: email.text.tidy).to_s
end
end.to_s
end
end
4 changes: 3 additions & 1 deletion lib/members_page.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

require_relative 'py_deputatos'
require_relative 'decrypted_email'
require_relative 'decrypt_email_addresses'

class MembersPage < PyDeputatos::HTML
decorator Scraped::Response::Decorator::CleanUrls
decorator DecryptEmailAddresses

field :members do
noko.css('table.tex tr').drop(1).map do |row|
Expand All @@ -13,6 +14,7 @@ class MembersPage < PyDeputatos::HTML
end

class MemberRow < PyDeputatos::HTML

field :id do
File.basename(tds[0].css('img/@src').text, '.jpg')
end
Expand Down

0 comments on commit d153856

Please sign in to comment.