Module: Macros::FGDC

Defined in:
lib/macros/fgdc.rb

Overview

Macros for extracting FGDC values from Nokogiri documents

Instance Method Summary collapse

Instance Method Details

#extract_uuid(record, context) ⇒ Object


15
16
17
18
19
20
21
22
# File 'lib/macros/fgdc.rb', line 15

def extract_uuid(record, context)
  institution = context.settings.fetch('agg_provider')
  if institution.include?('Harvard')
    harvard_uuid(record)
  else
    record.xpath('/*/spdoinfo/ptvctinf/sdtsterm/@Name').map(&:text)
  end
end

#generate_fgdc_id(prefixed: false) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/macros/fgdc.rb', line 24

def generate_fgdc_id(prefixed: false)
  lambda { |record, accumulator, context|
    identifier = select_identifier(record, context)

    next if identifier.blank?

    accumulator << if prefixed
                     identifier_with_prefix(context, identifier)
                   else
                     identifier
                   end
  }
end

#harvard_uuid(record) ⇒ Object


10
11
12
13
# File 'lib/macros/fgdc.rb', line 10

def harvard_uuid(record)
  urls = record.xpath('/*/idinfo/citation/citeinfo/onlink', TrajectPlus::Macros::FGCD::NS).map(&:text)
  urls.first.split('CollName=')[1]
end

#normalize_typeObject


6
7
8
# File 'lib/macros/fgdc.rb', line 6

def normalize_type
  extract_fgdc('/*/idinfo/citation/citeinfo/geoform', translation_map: 'types')
end

#select_identifier(record, context) ⇒ Object


38
39
40
41
# File 'lib/macros/fgdc.rb', line 38

def select_identifier(record, context)
  uuid = extract_uuid(record, context)
  uuid.presence || default_identifier(context)
end