Class: Stratagem::Crawler::SiteModel::PageSet

Inherits:
Object
  • Object
show all
Includes:
HtmlUtils
Defined in:
lib/stratagem/crawler/site_model/page_set.rb

Constant Summary

Constants included from HtmlUtils

HtmlUtils::INPUT_BUTTON, HtmlUtils::INPUT_RADIO, HtmlUtils::INPUT_TEXT, HtmlUtils::INPUT_TOGGLE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HtmlUtils

#find_login_form, #parse_forms

Constructor Details

#initialize(name) ⇒ PageSet

Returns a new instance of PageSet.



9
10
11
12
13
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 9

def initialize(name)
  @name = name
  @pages = []
  @edges = []
end

Instance Attribute Details

#authenticationObject

Returns the value of attribute authentication.



7
8
9
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 7

def authentication
  @authentication
end

#edgesObject (readonly)

Returns the value of attribute edges.



6
7
8
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 6

def edges
  @edges
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 6

def name
  @name
end

#pagesObject (readonly)

Returns the value of attribute pages.



6
7
8
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 6

def pages
  @pages
end

Instance Method Details

#add(route, controller, request, response, invocations = [], model_changes = {}, &block) ⇒ Object



43
44
45
46
47
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 43

def add(route, controller, request, response, invocations=[], model_changes={}, &block)
  page = Page.new(self, controller, request, response, invocations, model_changes, &block)
  self.pages << page
  page
end

#add_edge(from, to, type) ⇒ Object



39
40
41
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 39

def add_edge(from,to,type)
  self.edges << Edge.new(from,to,type)
end

#exportObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 15

def export
  puts "Exporting page set #{name} with #{@pages.size} initial pages"
  pages = @pages.select {|page| page.response_body && page.response_body.size > 0 }
  puts "\t#{pages.size} filtered pages"
  pages = pages.map {|page| page.export }

  pages << authentication..export if authentication && authentication.
  pages << authentication.response_page.export if authentication && authentication.response_page
  
  puts "\t#{pages.size} exported pages"
  {
    :name => name,
    :pages_attributes => pages,
    :edges_attributes => @edges.map {|edge| edge.export },
    :authentication_attributes => authentication.nil? ? nil : {
      :authenticated_user_id => authentication.authenticated_with.object_id,
      :success => authentication.success, 
      :login_page_external_id => authentication. ? authentication..object_id : nil, 
      :response_page_external_id => authentication.response_page ? authentication.response_page.object_id : nil,
      :ssl => authentication.ssl
    },
  }
end

#pages_for(id) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/stratagem/crawler/site_model/page_set.rb', line 49

def pages_for(id)
  if (id.kind_of?(String))
    pages.select {|page| page.url == id }
  else
    pages.select {|page| page.route == id }
  end
end