Module: Relaton::Jis::Bibliography

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

Instance Method Summary collapse

Instance Method Details

#get(ref, year = nil, opts = {}) ⇒ Relaton::Jis::Item?

Get JIS document by reference

Parameters:

  • ref (String)

    JIS document reference

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

    JIS document year

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

    options

Options Hash (opts):

  • :all_parts (Boolean)

    return all parts of document

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/relaton/jis/bibliography.rb', line 41

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? Bib::ItemData
    Util.info "Found: `#{result.docidentifier[0].content}`", key: ref
    return result
  end
  hint result, ref, year
end

#hint(result, ref, year) ⇒ Object

Log hint message

Parameters:

  • result (Array)

    search result (missed edition years)

  • ref (String)

    reference to search

  • year (String, nil)

    year to search



65
66
67
68
69
70
71
72
# File 'lib/relaton/jis/bibliography.rb', line 65

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) ⇒ Relaton::Jis::HitCollection?

Search JIS by reference, returning the full candidate collection.

The reference is parsed into a Pubid::Jis::Identifier and matched against the pubid-based ‘index-v2` via HitCollection. Candidates share the reference’s series and number (a supplement is filed under its base number), so an edition and its amendments are returned together.

Parameters:

  • code (String)

    JIS document code

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

    JIS document year

Returns:



22
23
24
25
26
27
28
29
# File 'lib/relaton/jis/bibliography.rb', line 22

def search(code, year = nil)
  pubid = ::Pubid::Jis::Identifier.parse code
  pubid.year ||= year.to_i if year
  HitCollection.new pubid
rescue StandardError => e
  Util.warn "Unable to parse `#{code}` with pubid: #{e.message}"
  nil
end