Class: QRDA::Cat1::NarrativeReferenceHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/qrda-import/narrative_reference_handler.rb

Instance Method Summary collapse

Constructor Details

#initializeNarrativeReferenceHandler

Returns a new instance of NarrativeReferenceHandler.



4
5
6
# File 'lib/qrda-import/narrative_reference_handler.rb', line 4

def initialize
  @id_map = {}
end

Instance Method Details

#build_id_map(doc) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/qrda-import/narrative_reference_handler.rb', line 8

def build_id_map(doc)
  path = "//*[@ID]"
  ids = doc.xpath(path)
  ids.each do |id|
    tag = id['ID']
    value = id.content
    @id_map[tag] = value
  end
end

#lookup_tag(tag) ⇒ String

Returns text description of tag.

Parameters:

  • tag (String)

Returns:

  • (String)

    text description of tag



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/qrda-import/narrative_reference_handler.rb', line 20

def lookup_tag(tag)
  value = @id_map[tag]
  # Not sure why, but sometimes the reference is #<Reference> and the ID value is <Reference>, and 
  # sometimes it is #<Reference>.  We look for both.
  if !value and tag[0] == '#'  
    tag = tag[1,tag.length]
    value = @id_map[tag]
  end

  value
end