Class: Gzlib::Search
Constant Summary collapse
- Search =
'http://opac.gzlib.gov.cn/opac/search?hasholding=1&'
- Para =
{page: 1, searchWay: 'title', sortWay: 'title200Weight', rows: 100, curlibcode: 'GT'}
- AcceptableSearchWay =
[:title, :marc, :isbn, :author, :subject, :class, :publish, :callno]
Instance Attribute Summary collapse
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
Class Method Summary collapse
Instance Method Summary collapse
- #[](i) ⇒ Object
- #curPage ⇒ Object
- #each(&b) ⇒ Object
-
#initialize(key, opt = {}) ⇒ Search
constructor
A new instance of Search.
- #lastPage? ⇒ Boolean
- #total ⇒ Object
Constructor Details
Instance Attribute Details
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
12 13 14 |
# File 'lib/gzlib/search.rb', line 12 def pages @pages end |
Class Method Details
.method_missing(search_way, *keywords, &blk) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/gzlib/search.rb', line 17 def method_missing search_way, *keywords, &blk opt = {searchWay: search_way} opt.merge! keywords.pop if keywords[-1].is_a? Hash return new(keywords.join(' '), opt) if AcceptableSearchWay.include? search_way super end |
Instance Method Details
#[](i) ⇒ Object
32 33 34 |
# File 'lib/gzlib/search.rb', line 32 def [](i) @books[i] end |
#curPage ⇒ Object
50 51 52 |
# File 'lib/gzlib/search.rb', line 50 def curPage @para[:page] end |
#each(&b) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/gzlib/search.rb', line 36 def each(&b) @books.each &b while not lastPage? nextPage books = getBooks(getHtml) @books.concat books books.each &b end end |
#lastPage? ⇒ Boolean
54 55 56 |
# File 'lib/gzlib/search.rb', line 54 def lastPage? curPage == pages end |
#total ⇒ Object
46 47 48 |
# File 'lib/gzlib/search.rb', line 46 def total reduce(0){ |sum, book| sum + 1 } end |