Skip to content

Commit

Permalink
adds in metadata transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
mejackreed committed Feb 18, 2015
1 parent 1fe5de8 commit 2510026
Show file tree
Hide file tree
Showing 18 changed files with 3,160 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--require spec_helper
3 changes: 3 additions & 0 deletions .travis.yml
@@ -0,0 +1,3 @@
language: ruby
rvm:
- 2.1.5
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -2,3 +2,5 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in geo_combine.gemspec
gemspec

gem 'coveralls', require: false
20 changes: 20 additions & 0 deletions Rakefile
@@ -1,3 +1,23 @@
require 'bundler/gem_tasks'

Dir.glob('lib/tasks/*.rake').each { |r| load r}

desc 'Run console for development'
task :console do
require 'irb'
require 'irb/completion'
require 'irb/ext/save-history'
require 'geo_combine'
ARGV.clear
IRB.start
end

begin
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
rescue LoadError
# no rspec available
end
2 changes: 2 additions & 0 deletions geo_combine.gemspec
Expand Up @@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency 'rsolr'
spec.add_dependency 'nokogiri'

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency 'rspec'
end
37 changes: 35 additions & 2 deletions lib/geo_combine.rb
@@ -1,7 +1,40 @@
require 'geo_combine/version'
require 'nokogiri'

module GeoCombine

##
# TODO: Create a parse method that can interpret the type of metadata being
# passed in.
#
# def self.parse metadata
# end

##
# Abstract class for GeoCombine objects
class Metadata
attr_reader :metadata

##
# Creates a new GeoCombine::Metadata object, where metadata parameter is can
# be a File path or String of XML
# @param (String) metadata can be a File path
# "./tmp/edu.stanford.purl/bb/338/jh/0716/iso19139.xml" or a String of XML
# metadata
def initialize metadata
metadata = File.read metadata if File.readable? metadata
metadata = Nokogiri::XML(metadata) if metadata.instance_of? String
@metadata = metadata
end

##
# Perform an XSLT tranformation on metadata using an object's XSL
def to_geoblacklight
GeoCombine::Geoblacklight.new(xsl.transform(@metadata))
end
end
end

load File.expand_path('../tasks/geo_combine.rake', __FILE__)
require 'geo_combine/fgdc'
require 'geo_combine/geoblacklight'
require 'geo_combine/iso19139'
require 'geo_combine/version'
14 changes: 14 additions & 0 deletions lib/geo_combine/fgdc.rb
@@ -0,0 +1,14 @@
module GeoCombine

##
# FIXME: FGDC parsing, transformations are still experimental
class Fgdc < Metadata

##
# Returns a Nokogiri::XSLT object containing the FGDC to GeoBlacklight XSL
# @return (Nokogiri::XSLT)
def xsl
Nokogiri::XSLT(File.read('./lib/xslt/fgdc2geoBL.xsl'))
end
end
end
25 changes: 25 additions & 0 deletions lib/geo_combine/geoblacklight.rb
@@ -0,0 +1,25 @@
module GeoCombine
class Geoblacklight < Metadata

##
# Returns a string of JSON from a GeoBlacklight hash
# @return (String)
def to_json
to_hash.to_json
end

##
# Returns a hash from a GeoBlacklight object
# @return (Hash)
def to_hash
hash = {}
@metadata.css('field').each do |field|
(hash[field.attributes['name'].value] ||= []) << field.children.text
end
hash.collect do |key, value|
hash[key] = value.count > 1 ? { key => value } : { key => value[0] }
end
hash
end
end
end
12 changes: 12 additions & 0 deletions lib/geo_combine/iso19139.rb
@@ -0,0 +1,12 @@
module GeoCombine
class Iso19139 < Metadata

##
# Returns a Nokogiri::XSLT object containing the ISO19139 to GeoBlacklight
# XSL
# @return (Nokogiri::XSLT)
def xsl
Nokogiri::XSLT(File.read('./lib/xslt/iso2geoBL.xsl'))
end
end
end

0 comments on commit 2510026

Please sign in to comment.