Class: WWW::Mechanize::History
- Inherits:
-
Array
- Object
- Array
- WWW::Mechanize::History
- Defined in:
- lib/www/mechanize/history.rb
Overview
This class manages history for your mechanize object.
Instance Attribute Summary collapse
-
#max_size ⇒ Object
Returns the value of attribute max_size.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(max_size = nil) ⇒ History
constructor
A new instance of History.
- #initialize_copy(orig) ⇒ Object
- #pop ⇒ Object
- #push(page, uri = nil) ⇒ Object (also: #<<)
- #shift ⇒ Object
- #visited?(url) ⇒ Boolean
- #visited_page(url) ⇒ Object
Constructor Details
#initialize(max_size = nil) ⇒ History
Returns a new instance of History.
8 9 10 11 |
# File 'lib/www/mechanize/history.rb', line 8 def initialize(max_size = nil) @max_size = max_size @history_index = {} end |
Instance Attribute Details
#max_size ⇒ Object
Returns the value of attribute max_size.
6 7 8 |
# File 'lib/www/mechanize/history.rb', line 6 def max_size @max_size end |
Instance Method Details
#clear ⇒ Object
38 39 40 41 |
# File 'lib/www/mechanize/history.rb', line 38 def clear @history_index.clear super end |
#initialize_copy(orig) ⇒ Object
13 14 15 16 |
# File 'lib/www/mechanize/history.rb', line 13 def initialize_copy(orig) super @history_index = orig.instance_variable_get(:@history_index).dup end |
#pop ⇒ Object
52 53 54 55 56 57 |
# File 'lib/www/mechanize/history.rb', line 52 def pop return nil if length == 0 page = super remove_from_index(page) page end |
#push(page, uri = nil) ⇒ Object Also known as: <<
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/www/mechanize/history.rb', line 18 def push(page, uri = nil) super(page) @history_index[(uri ? uri : page.uri).to_s] = page if @max_size && self.length > @max_size while self.length > @max_size self.shift end end self end |
#shift ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/www/mechanize/history.rb', line 43 def shift return nil if length == 0 page = self[0] self[0] = nil super remove_from_index(page) page end |
#visited?(url) ⇒ Boolean
30 31 32 |
# File 'lib/www/mechanize/history.rb', line 30 def visited?(url) ! visited_page(url).nil? end |
#visited_page(url) ⇒ Object
34 35 36 |
# File 'lib/www/mechanize/history.rb', line 34 def visited_page(url) @history_index[(url.respond_to?(:uri) ? url.uri : url).to_s] end |