Class: Stratagem::Crawler::Page
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(site_model, controller, request, response, invocations, model_changes, &block) ⇒ Page
Returns a new instance of Page.
78
79
80
81
82
83
84
|
# File 'lib/stratagem/crawler/site_model.rb', line 78
def initialize(site_model, controller, request, response, invocations, model_changes, &block)
@site_model = site_model
@invocations = invocations
@model_changes = model_changes
@authenticity_checked = controller.authenticity_checked?
init(request, response, &block)
end
|
Instance Attribute Details
Returns the value of attribute document.
76
77
78
|
# File 'lib/stratagem/crawler/site_model.rb', line 76
def document
@document
end
|
Returns the value of attribute method.
74
75
76
|
# File 'lib/stratagem/crawler/site_model.rb', line 74
def method
@method
end
|
Returns the value of attribute path.
73
74
75
|
# File 'lib/stratagem/crawler/site_model.rb', line 73
def path
@path
end
|
#redirected_to ⇒ Object
Returns the value of attribute redirected_to.
75
76
77
|
# File 'lib/stratagem/crawler/site_model.rb', line 75
def redirected_to
@redirected_to
end
|
Returns the value of attribute response.
70
71
72
|
# File 'lib/stratagem/crawler/site_model.rb', line 70
def response
@response
end
|
Returns the value of attribute url.
72
73
74
|
# File 'lib/stratagem/crawler/site_model.rb', line 72
def url
@url
end
|
Instance Method Details
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/stratagem/crawler/site_model.rb', line 90
def export
h = {
:external_id => self.object_id,
:url => url,
:path => path,
:request_method => method,
:redirected_to_page_external_id => redirected_to ? redirected_to.object_id : nil,
:route_external_id => route ? route.object_id : nil,
:references => @invocations.map {|i| i.to_reference.export },
:model_changes => Hash[@model_changes.map {|model,changes| [model.object_id, changes] }].to_json,
:authenticity_checked => @authenticity_checked,
:parameters => @request.parameters.to_json
}
h
end
|
127
128
129
130
131
132
133
134
135
|
# File 'lib/stratagem/crawler/site_model.rb', line 127
def forms
@forms ||= begin
forms = self.parse_forms(@document)
forms.each do |form|
form.page = self
end
forms
end
end
|
#inbound_edges(type = nil) ⇒ Object
149
150
151
|
# File 'lib/stratagem/crawler/site_model.rb', line 149
def inbound_edges(type=nil)
@site_model.edges.select {|edge| (edge.to == self) && (type.nil? || (type == edge.type)) }
end
|
#init(request, response, &block) ⇒ Object
106
107
108
109
110
111
112
113
114
|
# File 'lib/stratagem/crawler/site_model.rb', line 106
def init(request, response, &block)
@request = request.clone
@response = response.clone
@url = request.url
@path = request.path
@method = request.method
@document = Nokogiri::HTML(response.body)
self.redirected_to = block.call(response.redirect_url) if response.redirect?
end
|
137
138
139
|
# File 'lib/stratagem/crawler/site_model.rb', line 137
def login_form
self.find_login_form(@document)
end
|
#outbound_edges(type = nil) ⇒ Object
145
146
147
|
# File 'lib/stratagem/crawler/site_model.rb', line 145
def outbound_edges(type=nil)
@site_model.edges.select {|edge| edge.from == self && (type.nil? || (type == edge.type)) }
end
|
#redirected? ⇒ Boolean
123
124
125
|
# File 'lib/stratagem/crawler/site_model.rb', line 123
def redirected?
!self.redirected_to.nil?
end
|
#reload(&block) ⇒ Object
116
117
118
119
120
121
|
# File 'lib/stratagem/crawler/site_model.rb', line 116
def reload(&block)
request,response = yield url
init(request, response) {|redirected_to| }
end
|
86
87
88
|
# File 'lib/stratagem/crawler/site_model.rb', line 86
def route
@route ||= Stratagem::Model::Application.instance.routes.recognize(self)
end
|
153
154
155
156
157
158
159
|
# File 'lib/stratagem/crawler/site_model.rb', line 153
def title
unless @title
title = (@document/'head title').first
@title = title.inner_html if title
end
@title
end
|
141
142
143
|
# File 'lib/stratagem/crawler/site_model.rb', line 141
def to_html
@document.to_html
end
|