Class: RelatonBib::Hit

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hit, hit_collection = nil) ⇒ Hit

Returns a new instance of Hit.

Parameters:



13
14
15
16
# File 'lib/relaton_bib/hit.rb', line 13

def initialize(hit, hit_collection = nil)
  @hit            = hit
  @hit_collection = WeakRef.new hit_collection if hit_collection
end

Instance Attribute Details

#hitArray<Hash> (readonly)

Returns:



9
10
11
# File 'lib/relaton_bib/hit.rb', line 9

def hit
  @hit
end

#hit_collectionRelatonBib::HitCollection



6
7
8
# File 'lib/relaton_bib/hit.rb', line 6

def hit_collection
  @hit_collection
end

Instance Method Details

#fetchObject



32
33
34
# File 'lib/relaton_bib/hit.rb', line 32

def fetch
  raise "Not implemented"
end

#inspectString

Returns:

  • (String)


24
25
26
27
28
29
30
# File 'lib/relaton_bib/hit.rb', line 24

def inspect
  "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)} " \
    "@text=\"#{@hit_collection&.text}\" " \
    "@fetched=\"#{!@fetch.nil?}\" " \
    "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" " \
    "@title=\"#{@hit[:code]}\">"
end

#to_sString

Returns:

  • (String)


19
20
21
# File 'lib/relaton_bib/hit.rb', line 19

def to_s
  inspect
end

#to_xml(**opts) ⇒ String

Returns XML.

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • :builder (Nokogiri::XML::Builder)

    XML builder

  • :bibdata (Boolean)
  • :lang (String, Symbol)

    language

Returns:

  • (String)

    XML



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

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