class Parser::Fitness

Public Instance Methods

next_page() click to toggle source
Calls superclass method Parser::Base#next_page
# File lib/fly_parser/sources/fitness.rb, line 5
def next_page
  super(:id => 'next_page')
end
parse_page() click to toggle source
# File lib/fly_parser/sources/fitness.rb, line 9
def parse_page
  # until next page exists
  links = @source.links_with(:class => 'article-headine__link')
  links.map do |link|
    href = link.href
    page = link.click
    article = page.search('div[itemscope]')
    title = article.search('.article-name').text()
    # images stuff
    wrapper = article.search('.article-text__wrapper')
    # if poster_image doesn't exists, it looks like strange promo ads, so skip it
    next if wrapper.search('.article_image__pic').first.nil?
    poster_image = @copyright[:url] + wrapper.search('.article_image__pic').first.attributes['src'].value
    wrapper.search('.article_image__pic').first.remove()
    wrapper.search('.article_image__pic')
    images = wrapper.search('.article_image__pic')
    # expand path for images
    images.map {|image| image.attributes['src'].value = image.attributes['src'].value.prepend(@copyright[:url]); image }
    # remove ad
    wrapper.search('.po_theme').remove()
    wrapper.search('a').remove_attr('href')

    {title: title, content: wrapper.inner_html, poster_image: poster_image}
  end.compact
end