Class: RelatonJis::HitCollection
- Inherits:
-
RelatonBib::HitCollection
- Object
- RelatonBib::HitCollection
- RelatonJis::HitCollection
- Defined in:
- lib/relaton_jis/hit_collection.rb
Instance Method Summary collapse
-
#find ⇒ Hash
Find hit in collection.
-
#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 ⇒ Hash
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 { bib: hit.fetch } if hit.match? ref_parts, y missed_years << hit.id_parts[:year] if y && hit.match?(ref_parts) end { missed_years: missed_years } end |
#parse_ref(ref) ⇒ Hash
Parse reference
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/relaton_jis/hit_collection.rb', line 47 def parse_ref(ref) %r{ ^(?<code>\w+\s\w\s?\d+) (?::(?<year>\d{4}))? (?:/(?<expl>EXPL(?:ANATION)?)(?:\s(?<expl_num>\d+))?)? (?:/(?<amd>AMDENDMENT)(?:\s(?<amd_num>\d+)(?::(?<amd_year>\d{4}))?)?)? }x =~ ref { code: code, 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
36 37 38 |
# File 'lib/relaton_jis/hit_collection.rb', line 36 def ref_parts @ref_parts ||= parse_ref text end |