Module: Navigation
- Included in:
- Blogbot
- Defined in:
- lib/blogbot/navigation.rb
Overview
Adds capability to navigate through posts pages.
Instance Method Summary collapse
-
#ascend ⇒ Object
Changes current Nokogiri element to its parent.
- #auto_ascend ⇒ Object
-
#crawl_popular ⇒ Object
Examine popular element and climb DOM tree until multiple links are present.
-
#find_parent ⇒ Object
Returns parent of current Nokogiri element.
-
#go_to_popular ⇒ Object
Sets current element to ‘Popular’ indicator.
-
#go_to_posts_page ⇒ Object
Navigates to posts page based off of store_posts_url.
- #locate_popular_links ⇒ Object
-
#previous_page ⇒ Object
Navigates to previous Mechanize page.
Instance Method Details
#ascend ⇒ Object
Changes current Nokogiri element to its parent.
32 33 34 35 36 37 38 |
# File 'lib/blogbot/navigation.rb', line 32 def ascend if @current_element.ancestors.empty? == true # no more room to ascend puts 'At highest element. Nothing left to ascend.' else @current_element = @current_element.parent end end |
#auto_ascend ⇒ Object
40 41 42 43 |
# File 'lib/blogbot/navigation.rb', line 40 def auto_ascend ascend until see_multiple_links? == true @current_element end |
#crawl_popular ⇒ Object
Examine popular element and climb DOM tree until multiple links are present.
58 59 60 61 |
# File 'lib/blogbot/navigation.rb', line 58 def crawl_popular go_to_popular auto_ascend end |
#find_parent ⇒ Object
Returns parent of current Nokogiri element
27 28 29 |
# File 'lib/blogbot/navigation.rb', line 27 def find_parent @parent = @current_element.parent # one element higher, the div container end |
#go_to_popular ⇒ Object
Sets current element to ‘Popular’ indicator.
16 17 18 19 20 21 22 23 24 |
# File 'lib/blogbot/navigation.rb', line 16 def go_to_popular if see_popular? == false puts 'Nothing says "Popular" on this page' else store_indicator @current_element = @indicator @current_element end end |
#go_to_posts_page ⇒ Object
Navigates to posts page based off of store_posts_url.
4 5 6 7 8 |
# File 'lib/blogbot/navigation.rb', line 4 def go_to_posts_page find_posts_url store_posts_url @current_page = @posts_url.click end |
#locate_popular_links ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/blogbot/navigation.rb', line 45 def locate_popular_links if possible_success? == false ignorance_error elsif see_popular? == true crawl_popular elsif see_posts? == true go_to_posts_page see_popular? == true ? crawl_popular : ignorance_error end end |
#previous_page ⇒ Object
Navigates to previous Mechanize page.
11 12 13 |
# File 'lib/blogbot/navigation.rb', line 11 def previous_page @current_page = @agent.get(@agent.back['href']) end |