Class: Pincers::Chenso::BrowsingContext
- Inherits:
-
Object
- Object
- Pincers::Chenso::BrowsingContext
- Defined in:
- lib/pincers/chenso/browsing_context.rb
Instance Method Summary collapse
- #back(_times = 1) ⇒ Object
- #current_url ⇒ Object
- #document ⇒ Object
- #forward(_times = 1) ⇒ Object
- #get_child(_id) ⇒ Object
-
#initialize(_http_client, _state = nil) ⇒ BrowsingContext
constructor
A new instance of BrowsingContext.
- #load_child(_id) ⇒ Object
- #push(_request) ⇒ Object
- #refresh ⇒ Object
Constructor Details
#initialize(_http_client, _state = nil) ⇒ BrowsingContext
Returns a new instance of BrowsingContext.
5 6 7 8 9 10 11 |
# 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 |
Instance Method Details
#back(_times = 1) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
21 22 23 |
# File 'lib/pincers/chenso/browsing_context.rb', line 21 def current_url @state ? @state.uri.to_s : nil end |
#document ⇒ Object
25 26 27 |
# File 'lib/pincers/chenso/browsing_context.rb', line 25 def document @state ? @state.document : nil end |
#forward(_times = 1) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# 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) ⇒ Object
13 14 15 |
# File 'lib/pincers/chenso/browsing_context.rb', line 13 def get_child(_id) @childs[_id] end |
#load_child(_id) ⇒ Object
17 18 19 |
# File 'lib/pincers/chenso/browsing_context.rb', line 17 def load_child(_id) @childs[_id] = self.class.new(@client, @state) end |
#push(_request) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
29 30 31 32 33 34 |
# File 'lib/pincers/chenso/browsing_context.rb', line 29 def refresh if @pointer >= 0 navigate @history[@pointer] end self end |