Skip to content

Commit

Permalink
basic harness for extracting metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Hardy committed Nov 12, 2015
1 parent 3d22d83 commit c0848bc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
34 changes: 34 additions & 0 deletions app/models/concerns/external_metadata_file_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,38 @@ def vector_file?
def external_metadata_file?
true
end

# Extracts properties from the constitutent external metadata file
# @return [Hash]
def extract_metadata
fn = "extract_#{conforms_to.downcase}_metadata"
if respond_to?(fn.to_sym)
send(fn, metadata_xml)
else
fail "Unsupported metadata standard: #{conforms_to}"
end
end

# Retrives data from PCDM::File
def metadata_xml
Nokogiri::XML('<empty/>') # TODO: Get XML from file
end

def extract_iso19139_metadata(doc)
{
title: doc.at_xpath('//identificationInfo/MD_DataIdentification/citation/CI_Citation/title').text
}
end

def extract_fgdc_metadata(doc)
{
title: doc.at_xpath('//idinfo/citation/citeinfo/title').text
}
end

def extract_mods_metadata(doc)
{
title: doc.at_xpath('//titleInfo/title').text
}
end
end
8 changes: 8 additions & 0 deletions app/models/concerns/image_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@ def external_metadata_file?
# def rasters_ids
# rasters.map(&:id)
# end

# Extracts properties from the constitutent external metadata file
# @return [Hash]
# TODO: Does not support multiple external metadata files
def extract_metadata
return {} if metadata_files.blank?
metadata_files.first.extract_metadata
end
end
8 changes: 8 additions & 0 deletions app/models/concerns/raster_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ def images
def image
images.first
end

# Extracts properties from the constitutent external metadata file
# @return [Hash]
# TODO: Does not support multiple external metadata files
def extract_metadata
return {} if metadata_files.blank?
metadata_files.first.extract_metadata
end
end
8 changes: 8 additions & 0 deletions app/models/concerns/vector_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ def external_metadata_file?
def rasters
aggregated_by.select { |parent| parent.class.included_modules.include?(::RasterBehavior) }
end

# Extracts properties from the constitutent external metadata file
# @return [Hash]
# TODO: Does not support multiple external metadata files
def extract_metadata
return {} if metadata_files.blank?
metadata_files.first.extract_metadata
end
end

0 comments on commit c0848bc

Please sign in to comment.