class Gared::Idea
Public Class Methods
new(opac_url)
click to toggle source
# File lib/gared/idea.rb, line 5 def initialize(opac_url) @browser = Watir::Browser.new :chrome, options: {args: ['--no-sandbox', '--headless']} @options = {opac_url: opac_url} end
Public Instance Methods
query_person(person)
click to toggle source
# File lib/gared/idea.rb, line 13 def query_person(person) end
query_persons(q)
click to toggle source
# File lib/gared/idea.rb, line 10 def query_persons(q) end
query_publication(publication)
click to toggle source
# File lib/gared/idea.rb, line 19 def query_publication(publication) end
query_publications(q)
click to toggle source
# File lib/gared/idea.rb, line 16 def query_publications(q) end
query_publications_by_person(person, ctx = nil)
click to toggle source
# File lib/gared/idea.rb, line 22 def query_publications_by_person(person, ctx = nil) @browser.goto @options[:opac_url] @browser.wait t = @browser.text_field(id: 'get_var_0') t.set(person) @browser.input(id: 'cb_update_0').click # "quick search" - not necessarily by author! @browser.wait ret = [] begin results = @browser.div(id: 'results_list') if results.exists? # total = @browser.div(:class => 'resultSum').text.scan(/מתוך\s+(\d+)/)[0][0].to_i stop = false until stop do trs = @browser.div(id: 'results_list').table.rows if trs.size > 0 trs.each do |tr| item = tr.tr.tds[1] urlpart = item.h5.a.href p = Publication.new(ctx) p.title = item.ps[0].text # first line is always the title. After that, all bets are off... item.ps.each{|para| st = para.text.strip p.author_line = st.sub('מחבר: ','') if st =~ /^מחבר:/ p.pub_year = st.sub('שנה לועזית:','').sub('שנת הוצאה:','') if st =~ /^שנה לועזית:/ or st =~ /^שנת הוצאה:/ } p.source_id = urlpart p.scanned = false h = Holding.new h.source_id = urlpart.scan(/book_id%3E(\d+)%3C/)[0][0] h.source_name = @options[:opac_url] p.add_holding(h) ret << p end nextlink = @browser.a(title: 'הבא') if nextlink.exists? nextlink.click @browser.wait else stop = true end end end # now that we've extracted everything useful from this page, iterate over the results to pick up additional details # ret.each do |item| # @browser.goto item.source_id # @browser.wait # item.source_id = @browser.tr(id: '1').span(:class => 'bidie').text # doesn't look like there's much more to learn from the Holdings screen, since we don't care if there's more than one copy or not # @browser.goto @browser.ul(id: 'itemTabs').li(id: '2').a.href # check holdings # h = Holding.new # h.source_id = item.source_id # h.source_name = @options[:opac_url] # item.add_holding(h) # end end rescue Exception puts $! end return ret end