Module: RelatonJis::Bibliography
Constant Summary collapse
- SOURCE =
"https://webdesk.jsa.or.jp/books/W11M".freeze
Instance Method Summary collapse
-
#get(ref, year = nil, opts = {}) ⇒ RelatonJis::BibliographicItem?
Get JIS document by reference.
-
#hint(result, ref, year) ⇒ Object
Log hint message.
-
#search(code, year = nil) ⇒ RelatonJis::HitCollection
Search JIS by keyword.
Instance Method Details
#get(ref, year = nil, opts = {}) ⇒ RelatonJis::BibliographicItem?
Get JIS document by reference
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/relaton_jis/bibliography.rb', line 36 def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength code = ref.sub(/\s\((all parts|規格群)\)/, "") opts[:all_parts] ||= !$1.nil? Util.warn "(#{ref}) Fetching from webdesk.jsa.or.jp ..." hits = search(code, year) unless hits hint [], ref, year return end result = opts[:all_parts] ? hits.find_all_parts : hits.find if result.is_a? RelatonJis::BibliographicItem Util.warn "(#{ref}) Found: `#{result.docidentifier[0].id}`" return result end hint result, ref, year end |
#hint(result, ref, year) ⇒ Object
Log hint message
60 61 62 63 64 65 66 67 |
# File 'lib/relaton_jis/bibliography.rb', line 60 def hint(result, ref, year) Util.warn "(#{ref}) Not found." if result.any? Util.warn "(#{ref}) TIP: No match for edition year `#{year}`, " \ "but matches exist for `#{result.uniq.join('`, `')}`." end nil end |
#search(code, year = nil) ⇒ RelatonJis::HitCollection
Search JIS by keyword
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/relaton_jis/bibliography.rb', line 15 def search(code, year = nil) agent = Mechanize.new resp = agent.post "#{SOURCE}0270/index", dantai: "JIS", bunsyo_id: code, searchtype2: "1", status_1: "1", status_2: "1" disp = JSON.parse resp.body # raise RelatonBib::RequestError, "No results found for #{code}" if disp["disp_screen"].nil? return unless disp["status"] result = agent.get "#{SOURCE}0070/index" HitCollection.new code, year, result: result.xpath("//div[@class='blockGenaral']") end |