Class: Rash
Instance Method Summary collapse
-
#[](key) ⇒ Hash, ...
Retrieves the value for a given key.
- #fetch ⇒ Object
-
#initialize(url, path) ⇒ Rash
constructor
A new instance of Rash.
-
#keys ⇒ Array<String, Symbol>
return all keys in the store as an array.
-
#size ⇒ Fixnum
return the size of the store as an integer.
Methods included from Memoizable
Constructor Details
#initialize(url, path) ⇒ Rash
27 28 29 30 31 32 |
# File 'lib/hoodie/rash.rb', line 27 def initialize(url, path) @url = url @path = path memoize [:fetch], Stash.new(DiskStash::Cache.new) @store = fetch end |
Instance Method Details
#[](key) ⇒ Hash, ...
Retrieves the value for a given key
50 51 52 |
# File 'lib/hoodie/rash.rb', line 50 def [](key) @store[key] end |
#fetch ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/hoodie/rash.rb', line 34 def fetch results = [] Anemone.crawl(@url, discard_page_bodies: true) do |anemone| anemone.on_pages_like(/\/#{@path}\/\w+\/\w+\.(ini|zip)$/i) do |page| results << page.to_hash end end results.reduce({}, :recursive_merge) end |
#keys ⇒ Array<String, Symbol>
return all keys in the store as an array
66 67 68 |
# File 'lib/hoodie/rash.rb', line 66 def keys @store.keys end |
#size ⇒ Fixnum
return the size of the store as an integer
58 59 60 |
# File 'lib/hoodie/rash.rb', line 58 def size @store.size end |