Class: RelatonJis::HitCollection
- Inherits:
-
RelatonBib::HitCollection
- Object
- RelatonBib::HitCollection
- RelatonJis::HitCollection
- Defined in:
- lib/relaton_jis/hit_collection.rb
Instance Method Summary collapse
-
#find ⇒ RelatonJis::BibliographicItem, Array<Strig>
Find hit in collection.
- #find_all_parts ⇒ Object
-
#initialize(text, year = nil, result:) ⇒ HitCollection
constructor
Initialize hit collection.
-
#parse_ref(ref) ⇒ Hash
Parse reference.
-
#ref_parts ⇒ Hash
Return parts of reference.
Constructor Details
#initialize(text, year = nil, result:) ⇒ HitCollection
Initialize hit collection
10 11 12 13 |
# File 'lib/relaton_jis/hit_collection.rb', line 10 def initialize(text, year = nil, result:) super text, year @array = result.map { |h| Hit.create h, self } end |
Instance Method Details
#find ⇒ RelatonJis::BibliographicItem, Array<Strig>
Find hit in collection
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/relaton_jis/hit_collection.rb', line 20 def find missed_years = [] y = year || ref_parts[:year] @array.each do |hit| return hit.fetch if hit.match? ref_parts, y missed_years << hit.id_parts[:year] if y && hit.match?(ref_parts) end missed_years end |
#find_all_parts ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/relaton_jis/hit_collection.rb', line 31 def find_all_parts hits = @array.select { |hit| hit.match? ref_parts, year, all_parts: true } item = hits.min_by { |i| i.id_parts[:part].to_i }.fetch.to_all_parts hits.each do |hit| next if hit.hit[:id] == item.docidentifier.first.id docid = RelatonBib::DocumentIdentifier.new id: hit.hit[:id], type: "JIS", primary: true fref = RelatonBib::FormattedRef.new content: hit.hit[:id] bibitem = BibliographicItem.new docid: [docid], formattedref: fref item.relation << RelatonBib::DocumentRelation.new(type: "instance", bibitem: bibitem) end item end |
#parse_ref(ref) ⇒ Hash
Parse reference
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/relaton_jis/hit_collection.rb', line 61 def parse_ref(ref) %r{ ^(?<code>\w+\s\w\s?\w+) (?:-(?<part>\w+))? (?::(?<year>\d{4}))? (?:/(?<expl>EXPL(?:ANATION)?)(?:\s(?<expl_num>\d+))?)? (?:/(?<amd>AMDENDMENT)(?:\s(?<amd_num>\d+)(?::(?<amd_year>\d{4}))?)?)? }x =~ ref { code: code, part: part, year: year, expl: expl, expl_num: expl_num, amd: amd, amd_num: amd_num, amd_year: amd_year } end |
#ref_parts ⇒ Hash
Return parts of reference
50 51 52 |
# File 'lib/relaton_jis/hit_collection.rb', line 50 def ref_parts @ref_parts ||= parse_ref text end |