Class: Mechanize::History
- Inherits:
-
Array
- Object
- Array
- Mechanize::History
- Defined in:
- lib/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
-
#inspect ⇒ Object
:nodoc:.
- #pop ⇒ Object
- #push(page, uri = nil) ⇒ Object (also: #<<)
- #shift ⇒ Object
- #visited?(uri) ⇒ Boolean (also: #visited_page)
Constructor Details
#initialize(max_size = nil) ⇒ History
Returns a new instance of History.
9 10 11 12 |
# File 'lib/mechanize/history.rb', line 9 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.
7 8 9 |
# File 'lib/mechanize/history.rb', line 7 def max_size @max_size end |
Instance Method Details
#clear ⇒ Object
51 52 53 54 |
# File 'lib/mechanize/history.rb', line 51 def clear @history_index.clear super end |
#initialize_copy(orig) ⇒ Object
14 15 16 17 |
# File 'lib/mechanize/history.rb', line 14 def initialize_copy(orig) super @history_index = orig.instance_variable_get(:@history_index).dup end |
#inspect ⇒ Object
:nodoc:
19 20 21 22 23 |
# File 'lib/mechanize/history.rb', line 19 def inspect # :nodoc: uris = map(&:uri).join ', ' "[#{uris}]" end |
#pop ⇒ Object
67 68 69 70 71 72 |
# File 'lib/mechanize/history.rb', line 67 def pop return nil if length == 0 page = super remove_from_index(page) page end |
#push(page, uri = nil) ⇒ Object Also known as: <<
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mechanize/history.rb', line 25 def push(page, uri = nil) super page index = uri ? uri : page.uri @history_index[index.to_s] = page shift while length > @max_size if @max_size self end |
#shift ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mechanize/history.rb', line 56 def shift return nil if length == 0 page = self[0] self[0] = nil super remove_from_index(page) page end |
#visited?(uri) ⇒ Boolean Also known as: visited_page
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mechanize/history.rb', line 38 def visited? uri page = @history_index[uri.to_s] return page if page # HACK uri = uri.dup uri.path = '/' if uri.path.empty? @history_index[uri.to_s] end |