Class: Kindai::Searcher

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/kindai/searcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keywordObject

Returns the value of attribute keyword.



5
6
7
# File 'lib/kindai/searcher.rb', line 5

def keyword
  @keyword
end

Class Method Details

.search(keyword) ⇒ Object



6
7
8
9
10
11
# File 'lib/kindai/searcher.rb', line 6

def self.search keyword
  Kindai::Util.logger.debug "keyword: #{keyword}"
  me = self.new
  me.keyword = keyword
  me
end

Instance Method Details

#eachObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/kindai/searcher.rb', line 17

def each
  (1..(1/0.0)).each{ |page|
    Kindai::Util.logger.debug "page #{page}"
    uris = result_for(@keyword, page)
    return if uris.empty?
    uris.each{ |uri|
      yield Kindai::Book.new_from_permalink(uri)
    }
  }
end

#lengthObject



13
14
15
# File 'lib/kindai/searcher.rb', line 13

def length
  @length ||= total_of(@keyword)
end