Module: Slaw::Grammars::ZA::Postprocess

Defined in:
lib/slaw/grammars/za/postprocess.rb

Instance Method Summary collapse

Instance Method Details

#postprocess(doc) ⇒ Object



7
8
9
10
11
# File 'lib/slaw/grammars/za/postprocess.rb', line 7

def postprocess(doc)
  Slaw::Parse::Blocklists.adjust_blocklists(doc)
  schedule_aliases(doc)
  doc
end

#schedule_aliases(doc) ⇒ Object

Correct aliases for schedules to use the full textual content of the heading element



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/slaw/grammars/za/postprocess.rb', line 14

def schedule_aliases(doc)
  for hcontainer in doc.xpath('//xmlns:doc/xmlns:mainBody/xmlns:hcontainer[@name="schedule"]')
    heading = hcontainer.at_xpath('./xmlns:heading')
    frbr_alias = hcontainer.at_xpath('../../xmlns:meta/xmlns:identification/xmlns:FRBRWork/xmlns:FRBRalias')

    if heading and frbr_alias
      text = heading.xpath('.//text()').map(&:text).join('') || frbr_alias['value']
      frbr_alias['value'] = text unless text.empty?
    end
  end
end