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:

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


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

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

Instance Attribute Details

#hitArray<Hash> (readonly)

Returns:



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

def hit
  @hit
end

#hit_collectionRelatonBib::HitCollection (readonly)



4
5
6
# File 'lib/relaton_bib/hit.rb', line 4

def hit_collection
  @hit_collection
end

Instance Method Details

#fetchObject



30
31
32
# File 'lib/relaton_bib/hit.rb', line 30

def fetch
  raise "Not implemented"
end

#inspectString

Returns:

  • (String)


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

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

#to_sString

Returns:

  • (String)


17
18
19
# File 'lib/relaton_bib/hit.rb', line 17

def to_s
  inspect
end

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

Parameters:

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


35
36
37
38
39
40
41
42
43
44
# File 'lib/relaton_bib/hit.rb', line 35

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