Module: Shodan::HasPages
Instance Method Summary collapse
-
#[](index) ⇒ Page
The page at a given index.
-
#each {|page| ... } ⇒ self
Iterates over every page, until an empty page is encountered.
-
#each_host {|host| ... } ⇒ self
Iterates over every host.
-
#each_on_page(index) {|host| ... } ⇒ Object
Iterates over the hosts in a page at a given index.
-
#each_on_pages(indices) {|host| ... } ⇒ self
Iterates over each host on the pages at the given indices.
-
#each_page(indices) {|page| ... } ⇒ self
Iterates over the pages at given indices.
-
#first_host ⇒ Host
The first host on the first page.
-
#first_page ⇒ Page
The first page.
-
#host_at(index) ⇒ Host
Returns the host at a given index.
-
#pages(indices) ⇒ Array<Page>
The pages at the given indices.
Instance Method Details
#[](index) ⇒ Page
The page at a given index.
44 45 46 |
# File 'lib/shodan/has_pages.rb', line 44 def [](index) page_cache[index] end |
#each {|page| ... } ⇒ self
Iterates over every page, until an empty page is encountered.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/shodan/has_pages.rb', line 92 def each(&block) index = 1 until ((next_page = page_cache[index]).empty?) do block.call(next_page) index = index + 1 end return self end |
#each_host {|host| ... } ⇒ self
Iterates over every host.
114 115 116 |
# File 'lib/shodan/has_pages.rb', line 114 def each_host(&block) each { |page| page.each(&block) } end |
#each_on_page(index) {|host| ... } ⇒ Object
Iterates over the hosts in a page at a given index.
131 132 133 |
# File 'lib/shodan/has_pages.rb', line 131 def each_on_page(index,&block) page_cache[index].each(&block) end |
#each_on_pages(indices) {|host| ... } ⇒ self
Iterates over each host on the pages at the given indices.
150 151 152 |
# File 'lib/shodan/has_pages.rb', line 150 def each_on_pages(indices,&block) each_page(indices) { |page| page.each(&block) } end |
#each_page(indices) {|page| ... } ⇒ self
Iterates over the pages at given indices.
76 77 78 79 |
# File 'lib/shodan/has_pages.rb', line 76 def each_page(indices,&block) indices.map { |index| block.call(page_cache[index]) } return self end |
#first_host ⇒ Host
The first host on the first page.
160 161 162 |
# File 'lib/shodan/has_pages.rb', line 160 def first_host first_page.first end |
#first_page ⇒ Page
The first page.
31 32 33 |
# File 'lib/shodan/has_pages.rb', line 31 def first_page page_cache[1] end |
#host_at(index) ⇒ Host
Returns the host at a given index.
173 174 175 |
# File 'lib/shodan/has_pages.rb', line 173 def host_at(index) page(page_index_of(index))[result_index_of(index)] end |
#pages(indices) ⇒ Array<Page>
The pages at the given indices.
57 58 59 |
# File 'lib/shodan/has_pages.rb', line 57 def pages(indices) indices.map { |index| page_cache[index] } end |