Class: Brrowser::Tab
- Inherits:
-
Object
- Object
- Brrowser::Tab
- Defined in:
- lib/brrowser/tab.rb
Instance Attribute Summary collapse
-
#back_history ⇒ Object
readonly
Returns the value of attribute back_history.
-
#content ⇒ Object
Returns the value of attribute content.
-
#forms ⇒ Object
Returns the value of attribute forms.
-
#forward_history ⇒ Object
readonly
Returns the value of attribute forward_history.
-
#images ⇒ Object
Returns the value of attribute images.
-
#ix ⇒ Object
Returns the value of attribute ix.
-
#links ⇒ Object
Returns the value of attribute links.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #can_go_back? ⇒ Boolean
- #can_go_forward? ⇒ Boolean
- #go_back ⇒ Object
- #go_forward ⇒ Object
-
#initialize(url = nil) ⇒ Tab
constructor
A new instance of Tab.
- #navigate(new_url) ⇒ Object
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_history ⇒ Object (readonly)
Returns the value of attribute back_history.
4 5 6 |
# File 'lib/brrowser/tab.rb', line 4 def back_history @back_history end |
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/brrowser/tab.rb', line 3 def content @content end |
#forms ⇒ Object
Returns the value of attribute forms.
3 4 5 |
# File 'lib/brrowser/tab.rb', line 3 def forms @forms end |
#forward_history ⇒ Object (readonly)
Returns the value of attribute forward_history.
4 5 6 |
# File 'lib/brrowser/tab.rb', line 4 def forward_history @forward_history end |
#images ⇒ Object
Returns the value of attribute images.
3 4 5 |
# File 'lib/brrowser/tab.rb', line 3 def images @images end |
#ix ⇒ Object
Returns the value of attribute ix.
3 4 5 |
# File 'lib/brrowser/tab.rb', line 3 def ix @ix end |
#links ⇒ Object
Returns the value of attribute links.
3 4 5 |
# File 'lib/brrowser/tab.rb', line 3 def links @links end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/brrowser/tab.rb', line 3 def title @title end |
#url ⇒ Object
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
45 |
# File 'lib/brrowser/tab.rb', line 45 def can_go_back? = !@back_history.empty? |
#can_go_forward? ⇒ Boolean
46 |
# File 'lib/brrowser/tab.rb', line 46 def can_go_forward? = !@forward_history.empty? |
#go_back ⇒ Object
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_forward ⇒ Object
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 |
#navigate(new_url) ⇒ Object
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 |