Class: Stratagem::Crawler::SiteModel

Inherits:
Object
  • Object
show all
Includes:
HtmlUtils
Defined in:
lib/stratagem/crawler/site_model.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) ⇒ SiteModel

Returns a new instance of SiteModel.



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

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

Instance Attribute Details

#authenticationObject

Returns the value of attribute authentication.



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

def authentication
  @authentication
end

#edgesObject (readonly)

Returns the value of attribute edges.



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

def edges
  @edges
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pagesObject (readonly)

Returns the value of attribute pages.



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

def pages
  @pages
end

Instance Method Details

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



32
33
34
35
36
# File 'lib/stratagem/crawler/site_model.rb', line 32

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



28
29
30
# File 'lib/stratagem/crawler/site_model.rb', line 28

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

#exportObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/stratagem/crawler/site_model.rb', line 14

def export
  {
    :name => name,
    :pages => @pages.map {|page| page.export },
    :edges => @edges.map {|edge| edge.export },
    :authentication => authentication.nil? ? nil : {
      :success => authentication.success, 
      :login_page_external_id => authentication..object_id, 
      :response_page_external_id => authentication.response_page.object_id,
      :ssl => authentication.ssl
    },
  }
end

#pages_for(id) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/stratagem/crawler/site_model.rb', line 38

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