Class: Rash

Inherits:
Object show all
Includes:
Memoizable
Defined in:
lib/hoodie/rash.rb

Instance Method Summary collapse

Methods included from Memoizable

#memoize

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

#fetchObject



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

#keysArray<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

#sizeFixnum

return the size of the store as an integer



58
59
60
# File 'lib/hoodie/rash.rb', line 58

def size
  @store.size
end