Class: Parser::Exercise

Inherits:
Base
  • Object
show all
Defined in:
lib/fly_parser/sources/exercise.rb

Instance Method Summary collapse

Methods inherited from Base

#click, #collect_between, #copyright, #parse_all

Constructor Details

#initialize(url, options) ⇒ Exercise

Returns a new instance of Exercise.



4
5
6
7
# File 'lib/fly_parser/sources/exercise.rb', line 4

def initialize(url, options)
  @delay = 5
  super
end

Instance Method Details

#next_pageObject



8
9
10
# File 'lib/fly_parser/sources/exercise.rb', line 8

def next_page
  super(:class => 'nextpostslink')
end

#parse_pageObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fly_parser/sources/exercise.rb', line 12

def parse_page
  #until next page exists
  links = @source.links_with(:class => 'readmore')
  links.map do |link|
    page = link.click
    article = page.search('.post')
    title = article.search('.title').text()
    wrapper = article.search('.entry')
    wrapper.search('a').remove_attr('href')
    poster_image = wrapper.search('img').first.attributes['src'].value
    start_element = wrapper.at('p:nth-child(2)')
    end_element = wrapper.xpath("//comment()[. = ' adman_adcode_after ']").first
    next if start_element.next.nil?
    content = collect_between(start_element,end_element).map(&:to_s).join
    next if content.nil?
    {title: title, content: content, poster_image: poster_image}
  end.compact

end