Module: Reflection

Included in:
Blogbot
Defined in:
lib/blogbot/reflection.rb

Overview

Adds capability to examine for posts, articles, and links.

Instance Method Summary collapse

Instance Method Details

#possible_success?Boolean

Determines if bot can crawl a Popular section. If it doesn’t see popular at first glance, it searches and navigates to Posts page (Articles or Blog).

If Popular section still doesn’t exist, it’s a no-go.

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/blogbot/reflection.rb', line 35

def possible_success?
  if see_popular? == true
    true
  elsif see_posts? == true
    go_to_posts_page # Changes page to look for popular.
    answer =  see_popular? == true ? true : false # true if popular is present
    previous_page # Check is complete. Return to original page.
    answer
  else
    false
  end
end

#see_links?Boolean

Searches for presence of <a> tags in current element.

Returns:

  • (Boolean)


20
21
22
# File 'lib/blogbot/reflection.rb', line 20

def see_links?
  @current_element.css('a').empty? ? false : true
end

#see_multiple_links?Boolean

Searches for presences of more than two <a> tags in current element.

Returns:

  • (Boolean)


25
26
27
# File 'lib/blogbot/reflection.rb', line 25

def see_multiple_links?
  @current_element.css('a').length < 3 ? false : true
end

#see_popular?Boolean

Searches for keyword ‘Popular’ on current page.

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/blogbot/reflection.rb', line 14

def see_popular?
  search = @current_page.search "[text()*='Popular']"
  search.empty? ? false : true
end

#see_posts?Boolean

Searches for link that says articles or blog.

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'lib/blogbot/reflection.rb', line 4

def see_posts?
  find_posts_url
  if @article_link.nil? == true && @blog_link.nil? == true
    false # => no article links found
  else
    true
  end
end