class NewsScraper::Transformers::TrainerArticle
Public Class Methods
new(url:, payload:)
click to toggle source
Initialize a TrainerArticle
object
Params
-
url
: keyword arg - the url on which scraping was done -
payload
: keyword arg - the result of the scrape
Calls superclass method
NewsScraper::Transformers::Article::new
# File lib/news_scraper/transformers/trainer_article.rb, line 10 def initialize(url:, payload:) super(url: url, payload: payload) end
Public Instance Methods
transform()
click to toggle source
Transform the article
Returns
-
transformed_response
: tries all possible presets and returns a hash representing the results
# File lib/news_scraper/transformers/trainer_article.rb, line 19 def transform presets = NewsScraper.configuration.scrape_patterns['presets'] transformed_response = presets.each_with_object({}) do |(data_type, preset_options), response| response[data_type] = preset_options.each_with_object({}) do |(option, scrape_details), data_type_options| data = parsed_data(scrape_details['method'].to_sym, scrape_details['pattern']) data_type_options[option] = scrape_details.merge('data' => data) end end transformed_response.merge('url' => @url, 'root_domain' => @root_domain) end