Class: Medusa::PageStore
- Inherits:
-
Object
- Object
- Medusa::PageStore
- Extended by:
- Forwardable
- Defined in:
- lib/medusa/page_store.rb
Instance Method Summary collapse
-
#[](index) ⇒ Object
We typically index the hash with a URI, but convert it to a String for easier retrieval.
- #[]=(index, other) ⇒ Object
- #delete(key) ⇒ Object
- #each_value ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#has_page?(url) ⇒ Boolean
Does this PageStore contain the specified URL? HTTP and HTTPS versions of a URL are considered to be the same page.
-
#initialize(storage = {}) ⇒ PageStore
constructor
A new instance of PageStore.
- #touch_key(key) ⇒ Object
- #touch_keys(keys) ⇒ Object
-
#uniq! ⇒ Object
Removes all Pages from storage where redirect? is true.
- #values ⇒ Object
Constructor Details
#initialize(storage = {}) ⇒ PageStore
Returns a new instance of PageStore.
9 10 11 |
# File 'lib/medusa/page_store.rb', line 9 def initialize(storage = {}) @storage = storage end |
Instance Method Details
#[](index) ⇒ Object
We typically index the hash with a URI, but convert it to a String for easier retrieval
15 16 17 |
# File 'lib/medusa/page_store.rb', line 15 def [](index) @storage[index.to_s] end |
#[]=(index, other) ⇒ Object
19 20 21 |
# File 'lib/medusa/page_store.rb', line 19 def []=(index, other) @storage[index.to_s] = other end |
#delete(key) ⇒ Object
23 24 25 |
# File 'lib/medusa/page_store.rb', line 23 def delete(key) @storage.delete key.to_s end |
#each_value ⇒ Object
31 32 33 |
# File 'lib/medusa/page_store.rb', line 31 def each_value each { |key, value| yield value } end |
#has_key?(key) ⇒ Boolean
27 28 29 |
# File 'lib/medusa/page_store.rb', line 27 def has_key?(key) @storage.has_key? key.to_s end |
#has_page?(url) ⇒ Boolean
Does this PageStore contain the specified URL? HTTP and HTTPS versions of a URL are considered to be the same page.
51 52 53 54 55 56 57 58 59 |
# File 'lib/medusa/page_store.rb', line 51 def has_page?(url) schemes = %w(http https) if schemes.include? url.scheme u = url.dup return schemes.any? { |s| u.scheme = s; has_key?(u) } end has_key? url end |
#touch_key(key) ⇒ Object
41 42 43 |
# File 'lib/medusa/page_store.rb', line 41 def touch_key(key) self[key] = Page.new(key) end |
#touch_keys(keys) ⇒ Object
45 46 47 |
# File 'lib/medusa/page_store.rb', line 45 def touch_keys(keys) @storage.merge! keys.inject({}) { |h, k| h[k.to_s] = Page.new(k); h } end |
#uniq! ⇒ Object
Removes all Pages from storage where redirect? is true
64 65 66 67 |
# File 'lib/medusa/page_store.rb', line 64 def uniq! each_value { |page| delete page.url if page.redirect? } self end |
#values ⇒ Object
35 36 37 38 39 |
# File 'lib/medusa/page_store.rb', line 35 def values result = [] each { |key, value| result << value } result end |