Class: Rtml::ReverseEngineering::Crawler

Inherits:
Object
  • Object
show all
Defined in:
lib/rtml/reverse_engineering/crawler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Crawler

Returns a new instance of Crawler.



11
12
13
14
# File 'lib/rtml/reverse_engineering/crawler.rb', line 11

def initialize(options = {})
  @simulator = Rtml::ReverseEngineering::Simulator.new(options.delete(:tml))
  @session = ActionController::Integration::Session.new
end

Instance Attribute Details

#sessionObject (readonly)

Returns the value of attribute session.



2
3
4
# File 'lib/rtml/reverse_engineering/crawler.rb', line 2

def session
  @session
end

#simulatorObject (readonly)

Returns the value of attribute simulator.



2
3
4
# File 'lib/rtml/reverse_engineering/crawler.rb', line 2

def simulator
  @simulator
end

Instance Method Details

#current_screenObject



38
39
40
# File 'lib/rtml/reverse_engineering/crawler.rb', line 38

def current_screen
  route.last
end

#split_path_and_screen_name_out_of(path) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/rtml/reverse_engineering/crawler.rb', line 29

def split_path_and_screen_name_out_of(path)
  path, screen = path.split(/#/)
  if screen =~ /\?/
    screen, query = screen.split(/\?/)
    path = "#{path}?#{query}"
  end
  [path, screen]
end

#tml=(tml) ⇒ Object



6
7
8
9
# File 'lib/rtml/reverse_engineering/crawler.rb', line 6

def tml=(tml)
  @path = nil
  simulator.tml = tml
end

#visit(path, screen = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rtml/reverse_engineering/crawler.rb', line 16

def visit(path, screen = nil)
  path, screen = split_path_and_screen_name_out_of(path) unless screen
  unless path.blank? or path == @path
    get @path = path
    format = response.template.template_format
    if format == :rtml then simulator.tml = response.body
    else raise Rtml::Errors::InvalidFormat, "Response must be in :rtml format; found #{format.inspect}:\n#{response.body}"
    end
  end
  
  @simulator.visit screen
end