Class: Arstotzka::Crawler Private
- Inherits:
-
Object
- Object
- Arstotzka::Crawler
- Includes:
- Base
- Defined in:
- lib/arstotzka/crawler.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Crawl a hash through the keys of keys
Instance Method Summary collapse
-
#crawl(hash, index = 0) ⇒ Object
private
private
Fetch the value from hash by crawling the keys.
-
#initialize(options = {}, &block) ⇒ Crawler
constructor
private
Creates a new instance of Crawler.
-
#value(hash, index = 0) ⇒ Object
private
Crawls into the hash looking for all keys in the given keys.
Methods included from Base
Constructor Details
#initialize(options_hash = {}, &block) ⇒ Crawler #initialize(options, &block) ⇒ Crawler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new instance of Crawler
43 44 45 46 |
# File 'lib/arstotzka/crawler.rb', line 43 def initialize( = {}, &block) self. = @block = block end |
Instance Method Details
#crawl(hash, index = 0) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetch the value from hash by crawling the keys
The crawling is similar to fetching values in a chain { a: { b: 10 } }.fetch(:a).fetch(:b)
with added features like accessing string and symbol keys alike, wrapping the values in new objects, post processing the values, treating arrays as collection of hashes, etc…
Once the value is found (with final key), it is wrapped
If value found in any step (except finel step) and this is an Array, then next interations will happen with it element of the array, returning an array of results
162 163 164 165 166 167 |
# File 'lib/arstotzka/crawler.rb', line 162 def crawl(hash, index = 0) return wrap(hash) if reader.ended?(index) return crawl_array(hash, index) if hash.is_a?(Array) crawl(reader.read(hash, index), index + 1) end |
#value(hash, index = 0) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Crawls into the hash looking for all keys in the given keys
93 94 95 96 97 |
# File 'lib/arstotzka/crawler.rb', line 93 def value(hash, index = 0) crawl(hash, index) rescue Exception::KeyNotFound wrap(default) end |