class PointmdComments::Aggregators::Posts
Constants
- ALLOWED_SOURCES
NOTE: This array may be populated with other website sections in the future.
- DEFAULT_SOURCE
- MAIN_PAGE
Attributes
source[R]
urls[R]
Public Class Methods
new(source:, path:)
click to toggle source
# File lib/pointmd_comments/aggregators/posts.rb, line 11 def initialize(source:, path:) @source = source @path = path end
Public Instance Methods
call()
click to toggle source
# File lib/pointmd_comments/aggregators/posts.rb, line 16 def call validate_source fetch_posts puts "Found #{urls.count} links in the #{source} section.." @urls end
Private Instance Methods
download_html()
click to toggle source
# File lib/pointmd_comments/aggregators/posts.rb, line 54 def download_html Nokogiri::HTML(open('https://point.md/ru')) end
fetch_news_posts()
click to toggle source
# File lib/pointmd_comments/aggregators/posts.rb, line 42 def fetch_news_posts # NOTE: .post-blocks-wrap does not exist anymore # Find <article> tags instead articles = @page.css('article') @urls = articles.map do |article| article.css('a').last.attribute('href').to_s rescue StandardError => e puts e end.compact end
fetch_posts()
click to toggle source
# File lib/pointmd_comments/aggregators/posts.rb, line 32 def fetch_posts @page = download_html case source when :news fetch_news_posts when :today raise Errors::NotImplemented end end
validate_source()
click to toggle source
# File lib/pointmd_comments/aggregators/posts.rb, line 26 def validate_source return if ALLOWED_SOURCES.include? source raise ArgumentError, "Wrong source. Allowed sources are #{ALLOWED_SOURCES}" end