Class: RelatonIso::Hit

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_iso/hit.rb

Overview

Hit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hit, hit_collection = nil) ⇒ Hit

Returns a new instance of Hit.

Parameters:

  • hit (Hash)
  • hit_collection (RelatonIso:HitCollection) (defaults to: nil)


14
15
16
17
# File 'lib/relaton_iso/hit.rb', line 14

def initialize(hit, hit_collection = nil)
  @hit            = hit
  @hit_collection = hit_collection
end

Instance Attribute Details

#hitArray<Hash> (readonly)

Returns:

  • (Array<Hash>)


10
11
12
# File 'lib/relaton_iso/hit.rb', line 10

def hit
  @hit
end

#hit_collectionRelatonIso::HitCollection (readonly)



7
8
9
# File 'lib/relaton_iso/hit.rb', line 7

def hit_collection
  @hit_collection
end

Instance Method Details

#fetchRelatonIso::IsoBibliographicItem

Parse page.

Returns:

  • (RelatonIso::IsoBibliographicItem)


21
22
23
# File 'lib/relaton_iso/hit.rb', line 21

def fetch
  @fetch ||= Scrapper.parse_page @hit
end

#inspectString

Returns:

  • (String)


31
32
33
34
35
36
37
38
# File 'lib/relaton_iso/hit.rb', line 31

def inspect
  # matched_words = @hit["_highlightResult"].
  #   reduce([]) { |a, (_k, v)| a + v["matchedWords"] }.uniq

  "<#{self.class}:#{format('%#.14x', object_id << 1)} "\
  "@text=\"#{@hit_collection&.ref}\" "\
  "@reference=\"#{@hit["docRef"]}\""
end

#sort_weightObject



52
53
54
55
56
57
58
59
60
# File 'lib/relaton_iso/hit.rb', line 52

def sort_weight
  case hit["publicationStatus"]
  when "Published" then 0
  when "Under development" then 1
  when "Withdrawn" then 2
  else
    3
  end
end

#to_sString

Returns:

  • (String)


26
27
28
# File 'lib/relaton_iso/hit.rb', line 26

def to_s
  inspect
end

#to_xml(builder = nil, **opts) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder) (defaults to: nil)


41
42
43
44
45
46
47
48
49
50
# File 'lib/relaton_iso/hit.rb', line 41

def to_xml(builder = nil, **opts)
  if builder
    fetch.to_xml builder, **opts
  else
    builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
      fetch.to_xml xml, **opts
    end
    builder.doc.root.to_xml
  end
end