Class: NewsScraper::Transformers::TrainerArticle
- Defined in:
- lib/news_scraper/transformers/trainer_article.rb
Instance Method Summary collapse
-
#initialize(url:, payload:) ⇒ TrainerArticle
constructor
Initialize a TrainerArticle object.
-
#transform ⇒ Object
Transform the article.
Constructor Details
#initialize(url:, payload:) ⇒ TrainerArticle
Initialize a TrainerArticle object
Params
-
url
: keyword arg - the url on which scraping was done -
payload
: keyword arg - the result of the scrape
10 11 12 |
# File 'lib/news_scraper/transformers/trainer_article.rb', line 10 def initialize(url:, payload:) super(url: url, payload: payload) end |
Instance Method Details
#transform ⇒ Object
Transform the article
Returns
-
transformed_response
: tries all possible presets and returns a hash representing the results
19 20 21 22 23 24 25 26 27 28 |
# 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, ), response| response[data_type] = .each_with_object({}) do |(option, scrape_details), | data = parsed_data(scrape_details['method'].to_sym, scrape_details['pattern']) [option] = scrape_details.merge('data' => data) end end transformed_response.merge('url' => @url, 'root_domain' => @root_domain) end |