Class: Gbbib::Hit

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

Overview

Hit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid:, title:, hit_collection: nil, scrapper:) ⇒ Hit

Returns a new instance of Hit.

Parameters:

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


20
21
22
23
24
25
26
# File 'lib/gbbib/hit.rb', line 20

def initialize(pid:, title:, hit_collection: nil, scrapper:)
  @pid            = pid
  @title          = title
  @hit_collection = hit_collection
  @scrapper       = scrapper
  self.hit_collection << self if hit_collection
end

Instance Attribute Details

#hit_collectionIsobib::HitCollection (readonly)

Returns:

  • (Isobib::HitCollection)


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

def hit_collection
  @hit_collection
end

#pidString (readonly)

Returns:

  • (String)


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

def pid
  @pid
end

#scrapperGbbib::GbScrapper, ... (readonly)

Returns:



16
17
18
# File 'lib/gbbib/hit.rb', line 16

def scrapper
  @scrapper
end

#titleString (readonly)

Returns:

  • (String)


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

def title
  @title
end

Instance Method Details

#fetchIsobib::IsoBibliographicItem

Parse page.

Returns:

  • (Isobib::IsoBibliographicItem)


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

def fetch
  @fetch ||= scrapper.scrape_doc pid
end

#inspectString

Returns:

  • (String)


40
41
42
43
44
# File 'lib/gbbib/hit.rb', line 40

def inspect
  "<#{self.class}:#{format('%#.14x', object_id << 1)} "\
  "@fullIdentifier=\"#{@fetch&.shortref}\" "\
  "@title=\"#{title}\">"
end

#to_sString

Returns:

  • (String)


35
36
37
# File 'lib/gbbib/hit.rb', line 35

def to_s
  inspect
end

#to_xml(builder = nil, opts = {}) ⇒ String

Returns:

  • (String)


47
48
49
50
51
52
53
54
55
56
# File 'lib/gbbib/hit.rb', line 47

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