Class: Gared::Idea

Inherits:
Object
  • Object
show all
Defined in:
lib/gared/idea.rb

Instance Method Summary collapse

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) ⇒ 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
# File 'lib/gared/idea.rb', line 22

def query_publications_by_person(person)
  @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 = []
  results = @browser.div(id: 'results_list')
  if results.exists?
    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
        p.title = item.ps[0].text
        p.author_line = item.ps[1].text.sub('מחבר: ','')
        p.pub_year = item.ps[2].text.sub('שנה לועזית:','').sub('שנת הוצאה:','')

        p.source_id = urlpart
        ret << p
      end
      # now that we've extracted everything useful from this page, iterate over the results to pick up the system ID
      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
  end
  return ret
  # TODO: support multiple result pages
end