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
#initialize(key, opt = {}) ⇒ Search
Returns a new instance of Search.
23 24 25 26 27 28 |
# File 'lib/gzlib/search.rb', line 23 def initialize(key, opt={}) @para = Para.merge({q: escape(key)}).merge opt doc = getHtml @books = getBooks(doc) @pages = (@books.empty? ? 1 : getPages(doc)) end |
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 |
# File 'lib/gzlib/search.rb', line 17 def method_missing search_way, *keywords, &blk return new(keywords.join(' '), searchWay: search_way) if AcceptableSearchWay.include? search_way super end |
Instance Method Details
#[](i) ⇒ Object
30 31 32 |
# File 'lib/gzlib/search.rb', line 30 def [](i) @books[i] end |
#curPage ⇒ Object
48 49 50 |
# File 'lib/gzlib/search.rb', line 48 def curPage @para[:page] end |
#each(&b) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/gzlib/search.rb', line 34 def each(&b) @books.each &b while not lastPage? nextPage books = getBooks(getHtml) @books.concat books books.each &b end end |
#lastPage? ⇒ Boolean
52 53 54 |
# File 'lib/gzlib/search.rb', line 52 def lastPage? curPage == pages end |
#total ⇒ Object
44 45 46 |
# File 'lib/gzlib/search.rb', line 44 def total reduce(0){ |sum, book| sum + 1 } end |