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('%<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)


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

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



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

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