Class: RelatonJis::HitCollection

Inherits:
RelatonBib::HitCollection
  • Object
show all
Defined in:
lib/relaton_jis/hit_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(text, year = nil, result:) ⇒ HitCollection

Initialize hit collection

Parameters:

  • text (String)

    reference

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

    year

  • result (Nokogiri::XML::NodeSet)

    <description>



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

#findHash

Find hit in collection

Returns:

  • (Hash)

    hash with bib ot array of missed years



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

Parameters:

  • ref (String)

    reference

Returns:

  • (Hash)

    hash with parts of 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_partsHash

Return parts of reference

Returns:

  • (Hash)

    hash with parts of reference



36
37
38
# File 'lib/relaton_jis/hit_collection.rb', line 36

def ref_parts
  @ref_parts ||= parse_ref text
end