Class: NewsScraper::Transformers::Article
- Inherits:
-
Object
- Object
- NewsScraper::Transformers::Article
- Defined in:
- lib/news_scraper/transformers/article.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(url:, payload:) ⇒ Article
constructor
Initialize a Article object.
-
#transform ⇒ Object
Transform the article.
Constructor Details
#initialize(url:, payload:) ⇒ Article
Initialize a Article object
Params
-
url
: keyword arg - the url on which scraping was done -
payload
: keyword arg - the result of the scrape
19 20 21 22 23 |
# File 'lib/news_scraper/transformers/article.rb', line 19 def initialize(url:, payload:) @url = url @root_domain = URIParser.new(url).host @payload = payload end |
Instance Method Details
#transform ⇒ Object
Transform the article
Raises
-
ScrapePatternNotDefined: will raise this error if the root domain is not in the article_scrape_patterns.yml
Returns
-
transformed_response
: the response that has been parsed and transformed to a hash
33 34 35 36 37 |
# File 'lib/news_scraper/transformers/article.rb', line 33 def transform scrape_details = NewsScraper.configuration.scrape_patterns['domains'][@root_domain] raise ScrapePatternNotDefined.new(url: @url, root_domain: @root_domain) unless scrape_details transformed_response(scrape_details).merge(url: @url, root_domain: @root_domain) end |