Class: Gared::Idea
- Inherits:
-
Object
- Object
- Gared::Idea
- Defined in:
- lib/gared/idea.rb
Instance Method Summary collapse
-
#initialize(opac_url) ⇒ Idea
constructor
A new instance of Idea.
- #query_person(person) ⇒ Object
- #query_persons(q) ⇒ Object
- #query_publication(publication) ⇒ Object
- #query_publications(q) ⇒ Object
- #query_publications_by_person(person, ctx = nil) ⇒ Object
Constructor Details
#initialize(opac_url) ⇒ Idea
Returns a new instance of Idea.
5 6 7 8 |
# 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 |
Instance Method Details
#query_person(person) ⇒ Object
13 14 |
# File 'lib/gared/idea.rb', line 13 def query_person(person) end |
#query_persons(q) ⇒ Object
10 11 |
# File 'lib/gared/idea.rb', line 10 def query_persons(q) end |
#query_publication(publication) ⇒ Object
19 20 |
# File 'lib/gared/idea.rb', line 19 def query_publication(publication) end |
#query_publications(q) ⇒ Object
16 17 |
# File 'lib/gared/idea.rb', line 16 def query_publications(q) end |
#query_publications_by_person(person, ctx = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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. = st.sub('מחבר: ','') if st =~ /^מחבר:/ p.pub_year = st.sub('שנה לועזית:','').sub('שנת הוצאה:','') if st =~ /^שנה לועזית:/ or st =~ /^שנת הוצאה:/ } p.source_id = urlpart 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 |