class Pincers::Chenso::BrowsingContext

Public Class Methods

new(_http_client, _state=nil) click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 5
def initialize(_http_client, _state=nil)
  @client = _http_client
  @history = []
  @pointer = -1
  @childs = {}
  @state = _state
end

Public Instance Methods

back(_times=1) click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 46
def back(_times=1)
  # not sure about this: for now, back will stop at the first request
  if @pointer < 0
    nil
  elsif _times >= @pointer
    change_pointer 0
  else
    change_pointer @pointer - _times
  end
  self
end
current_url() click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 21
def current_url
  @state ? @state.uri.to_s : nil
end
document() click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 25
def document
  @state ? @state.document : nil
end
forward(_times=1) click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 58
def forward(_times=1)
  max_pointer = @history.length - 1
  if _times >= max_pointer - @pointer
    change_pointer max_pointer
  else
    change_pointer @pointer + _times
  end
  self
end
get_child(_id) click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 13
def get_child(_id)
  @childs[_id]
end
load_child(_id) click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 17
def load_child(_id)
  @childs[_id] = self.class.new(@client, @state)
end
push(_request) click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 36
def push(_request)
  _request.fix_uri @state

  @history.slice!(@pointer+1..-1)
  @history.push _request
  @pointer += 1
  navigate _request
  self
end
refresh() click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 29
def refresh
  if @pointer >= 0
    navigate @history[@pointer]
  end
  self
end

Private Instance Methods

change_pointer(_new_pointer) click to toggle source
# File lib/pincers/chenso/browsing_context.rb, line 70
def change_pointer(_new_pointer)
  if _new_pointer != @pointer
    @pointer = _new_pointer
    navigate @history[@pointer]
  else nil end
end
navigate(_request) click to toggle source