Module: RelatonJis::Bibliography

Extended by:
Bibliography
Included in:
Bibliography
Defined in:
lib/relaton_jis/bibliography.rb

Constant Summary collapse

SOURCE =
"https://webdesk.jsa.or.jp/books/W11M".freeze

Instance Method Summary collapse

Instance Method Details

#get(ref, year = nil, _opts = {}) ⇒ RelatonJis::BibliographicItem?

Get JIS document by reference

Parameters:

  • ref (String)

    JIS document reference

  • year (String) (defaults to: nil)

    JIS document year

  • _opts (Hash) (defaults to: {})

    options

Returns:



32
33
34
35
36
37
38
39
40
# File 'lib/relaton_jis/bibliography.rb', line 32

def get(ref, year = nil, _opts = {})
  warn "[relaton-jis] (\"#{ref}\") fetching..."
  result = search(ref, year).find
  if result[:bib]
    warn "[relaton-jis] (\"#{ref}\") found #{result[:bib].docidentifier[0].id}"
    return result[:bib]
  end
  hint result, ref, year
end

#hint(result, ref, year) ⇒ Object

Log hint message

Parameters:

  • result (Hash)

    search result

  • ref (String)

    reference to search

  • year (String, nil)

    year to search



49
50
51
52
53
54
55
56
# File 'lib/relaton_jis/bibliography.rb', line 49

def hint(result, ref, year)
  warn "[relaton-jis] (\"#{ref}\") not found. The identifier must be " \
       "exactly as shown on the webdesk.jsa.or.jp website."
  if result[:missed_years]
    warn "[relaton-jis] (\"#{ref}\") TIP: No match for edition year #{year}, " \
         "but matches exist for #{result[:missed_years].uniq.join(', ')}."
  end
end

#search(code, year = nil) ⇒ RelatonJis::HitCollection

Search JIS by keyword

Parameters:

  • code (String)

    JIS documetnt code

  • year (String, nil) (defaults to: nil)

    JIS document year

Returns:



15
16
17
18
19
20
21
# File 'lib/relaton_jis/bibliography.rb', line 15

def search(code, year = nil)
  agent = Mechanize.new
  resp = agent.post "#{SOURCE}0010/searchByKeyword", search_type: "JIS", keyword: code
  disp = JSON.parse resp.body
  result = agent.get "#{SOURCE}#{disp['disp_screen']}/index"
  HitCollection.new code, year, result: result.xpath("//div[@class='blockGenaral']")
end