From d15385658408aceee9fcec7596cc0f80883d501c Mon Sep 17 00:00:00 2001 From: Oliver Denman Date: Tue, 23 May 2017 17:57:28 +0100 Subject: [PATCH] WIP: Use decorator --- lib/decrypt_email_addresses.rb | 14 ++++++++++++++ lib/members_page.rb | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 lib/decrypt_email_addresses.rb diff --git a/lib/decrypt_email_addresses.rb b/lib/decrypt_email_addresses.rb new file mode 100644 index 0000000..f86a954 --- /dev/null +++ b/lib/decrypt_email_addresses.rb @@ -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 diff --git a/lib/members_page.rb b/lib/members_page.rb index 96e64a0..94ed2f4 100644 --- a/lib/members_page.rb +++ b/lib/members_page.rb @@ -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| @@ -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