Module: RelatonJis::Bibliography
Constant Summary collapse
- GH_URL =
SOURCE = “webdesk.jsa.or.jp/books/W11M”.freeze
"https://raw.githubusercontent.com/relaton/relaton-data-jis/refs/heads/main/".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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/relaton_jis/bibliography.rb', line 32 def get(ref, year = nil, opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength code = ref.sub(/\s\((all parts|規格群)\)/, "") opts[:all_parts] ||= !$1.nil? Util.info "Fetching from webdesk.jsa.or.jp ...", key: ref 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.info "Found: `#{result.docidentifier[0].id}`", key: ref return result end hint result, ref, year end |
#hint(result, ref, year) ⇒ Object
Log hint message
56 57 58 59 60 61 62 63 |
# File 'lib/relaton_jis/bibliography.rb', line 56 def hint(result, ref, year) Util.info "Not found.", key: ref if result.any? Util.info "TIP: No match for edition year `#{year}`, but " \ "matches exist for `#{result.uniq.join('`, `')}`.", key: ref end nil end |
#search(code, year = nil) ⇒ RelatonJis::HitCollection
Search JIS by keyword
16 17 18 19 20 |
# File 'lib/relaton_jis/bibliography.rb', line 16 def search(code, year = nil) index = Relaton::Index.find_or_create(:jis, url: "#{GH_URL}index-v1.zip", file: DataFetcher::INDEX_FILE) result = index.search(code).sort_by { |h| h[:id] } HitCollection.new code, year, result: result # .xpath("//div[@class='blockGenaral']") end |