Class: Brrowser::Tab

Inherits:
Object
  • Object
show all
Defined in:
lib/brrowser/tab.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil) ⇒ Tab

Returns a new instance of Tab.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/brrowser/tab.rb', line 6

def initialize(url = nil)
  @url             = url
  @title           = ""
  @content         = ""
  @ix              = 0
  @links           = []
  @forms           = []
  @images          = []
  @back_history    = []
  @forward_history = []
end

Instance Attribute Details

#back_historyObject (readonly)

Returns the value of attribute back_history.



4
5
6
# File 'lib/brrowser/tab.rb', line 4

def back_history
  @back_history
end

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/brrowser/tab.rb', line 3

def content
  @content
end

#formsObject

Returns the value of attribute forms.



3
4
5
# File 'lib/brrowser/tab.rb', line 3

def forms
  @forms
end

#forward_historyObject (readonly)

Returns the value of attribute forward_history.



4
5
6
# File 'lib/brrowser/tab.rb', line 4

def forward_history
  @forward_history
end

#imagesObject

Returns the value of attribute images.



3
4
5
# File 'lib/brrowser/tab.rb', line 3

def images
  @images
end

#ixObject

Returns the value of attribute ix.



3
4
5
# File 'lib/brrowser/tab.rb', line 3

def ix
  @ix
end

Returns the value of attribute links.



3
4
5
# File 'lib/brrowser/tab.rb', line 3

def links
  @links
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/brrowser/tab.rb', line 3

def title
  @title
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/brrowser/tab.rb', line 3

def url
  @url
end

Instance Method Details

#can_go_back?Boolean

Returns:

  • (Boolean)


45
# File 'lib/brrowser/tab.rb', line 45

def can_go_back?    = !@back_history.empty?

#can_go_forward?Boolean

Returns:

  • (Boolean)


46
# File 'lib/brrowser/tab.rb', line 46

def can_go_forward? = !@forward_history.empty?

#go_backObject



27
28
29
30
31
32
33
34
# File 'lib/brrowser/tab.rb', line 27

def go_back
  return nil if @back_history.empty?
  @forward_history.push({ url: @url, ix: @ix })
  prev = @back_history.pop
  @url = prev[:url]
  @ix  = prev[:ix]
  @url
end

#go_forwardObject



36
37
38
39
40
41
42
43
# File 'lib/brrowser/tab.rb', line 36

def go_forward
  return nil if @forward_history.empty?
  @back_history.push({ url: @url, ix: @ix })
  nxt = @forward_history.pop
  @url = nxt[:url]
  @ix  = nxt[:ix]
  @url
end


18
19
20
21
22
23
24
25
# File 'lib/brrowser/tab.rb', line 18

def navigate(new_url)
  if @url
    @back_history.push({ url: @url, ix: @ix })
  end
  @forward_history.clear
  @url = new_url
  @ix  = 0
end