Class: RelatonJis::Hit

Inherits:
RelatonBib::Hit
  • Object
show all
Defined in:
lib/relaton_jis/hit.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(node, collection) ⇒ RelatonJis::Hit

Create new hit

Parameters:

Returns:



11
12
13
14
15
# File 'lib/relaton_jis/hit.rb', line 11

def self.create(node, collection)
  a = node.at("./a")
  hit = { id: a.at("./text()").text.strip, url: a["href"] }
  new hit, collection
end

Instance Method Details

#fetchObject



44
45
46
# File 'lib/relaton_jis/hit.rb', line 44

def fetch
  @fetch ||= Scraper.new(hit[:url]).fetch
end

#id_partsHash

Return parts of document id

Returns:

  • (Hash)

    hash with parts of document id



40
41
42
# File 'lib/relaton_jis/hit.rb', line 40

def id_parts
  @id_parts ||= hit_collection.parse_ref hit[:id]
end

#match?(ref_parts, year = nil) ⇒ Boolean

Check if hit matches reference

Parameters:

  • ref_parts (Hash)

    parts of reference

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

    year

Returns:

  • (Boolean)

    true if hit matches reference



25
26
27
28
29
30
31
32
33
# File 'lib/relaton_jis/hit.rb', line 25

def match?(ref_parts, year = nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
  id_parts[:code].include?(ref_parts[:code]) &&
    (year.nil? || year == id_parts[:year]) &&
    ((ref_parts[:expl].nil? || !id_parts[:expl].nil?) &&
     (ref_parts[:expl_num].nil? || ref_parts[:expl_num] == id_parts[:expl_num])) &&
    ((ref_parts[:amd].nil? || !id_parts[:amd].nil?) &&
      (ref_parts[:amd_num].nil? || ref_parts[:amd_num] == id_parts[:amd_num]) &&
      (ref_parts[:amd_year].nil? || ref_parts[:amd_year] == id_parts[:amd_year]))
end