geo_combine 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 568a1667dfa82c56c109fe121503a70a84d2f876
4
- data.tar.gz: e0787b2029cdf7755bdf0790add73b35578d9892
3
+ metadata.gz: 66720182889b98a3b1ef96cbdf22f454a90550bf
4
+ data.tar.gz: 5ec28f72313b22ba934b0ee3e093fedbfcc0c4d7
5
5
  SHA512:
6
- metadata.gz: 4b73e9f0895b8892ec1f87b3f2ce77e7157f6940ac4822367a8f733167b7d0496a0ca41f6e2efe4dedb49ba2a4b968e1bed05bd13971352a4fd0c02ff848502b
7
- data.tar.gz: aec8e584e9278992a7b90e015ea8dfab83afe153160da20ec4041e5b0588df261fedb6b86d460cb375f94310a6b6c5cffba462d4c813861f3ed0d79ab019acc4
6
+ metadata.gz: 89d15e4a3612d245b017cbcd901a460670e55c6c4c49add06b29da0e56ae3a2c8a4d2fbecf28fa1cfb5e41768da9817b029219007df823343a2cb8b16d84e98e
7
+ data.tar.gz: ced995dcb3f7cefb677ee22cfb95c09c99293875e509cb197f53d9aaf2c63e269dce9fe7011a90c2bd0b2a794a0be4b06336c5b5b095c10d19b16eac11140e13
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in geo_combine.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -19,6 +19,20 @@ Or install it yourself as:
19
19
  $ gem install geo_combine
20
20
 
21
21
  ## Usage
22
+ GeoCombine can be used as a set of rake tasks for cloning, updating, and indexing OpenGeoMetdata metdata. It can also be used as a Ruby library for converting metdata.
23
+
24
+ ### Transforming metadata
25
+
26
+ ```ruby
27
+ # Create a new ISO19139 object
28
+ > iso_metadata = GeoCombine::Iso19139.new('./tmp/edu.stanford.purl/bb/338/jh/0716/iso19139.xml')
29
+
30
+ # Convert it to GeoBlacklight
31
+ > iso_metadata.to_geoblacklight
32
+
33
+ # Convert that to JSON
34
+ > iso_metadata.to_geoblacklight.to_json
35
+ ```
22
36
 
23
37
  ### Clone all OpenGeoMetadata repositories
24
38
 
data/Rakefile CHANGED
@@ -1,3 +1,23 @@
1
1
  require 'bundler/gem_tasks'
2
2
 
3
3
  Dir.glob('lib/tasks/*.rake').each { |r| load r}
4
+
5
+ desc 'Run console for development'
6
+ task :console do
7
+ require 'irb'
8
+ require 'irb/completion'
9
+ require 'irb/ext/save-history'
10
+ require 'geo_combine'
11
+ ARGV.clear
12
+ IRB.start
13
+ end
14
+
15
+ begin
16
+ require 'rspec/core/rake_task'
17
+
18
+ RSpec::Core::RakeTask.new(:spec)
19
+
20
+ task :default => :spec
21
+ rescue LoadError
22
+ # no rspec available
23
+ end
data/geo_combine.gemspec CHANGED
@@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'rsolr'
22
+ spec.add_dependency 'nokogiri'
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.7"
24
25
  spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency 'rspec'
25
27
  end
@@ -0,0 +1,14 @@
1
+ module GeoCombine
2
+
3
+ ##
4
+ # FIXME: FGDC parsing, transformations are still experimental
5
+ class Fgdc < Metadata
6
+
7
+ ##
8
+ # Returns a Nokogiri::XSLT object containing the FGDC to GeoBlacklight XSL
9
+ # @return (Nokogiri::XSLT)
10
+ def xsl
11
+ Nokogiri::XSLT(File.read('./lib/xslt/fgdc2geoBL.xsl'))
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module GeoCombine
2
+ class Geoblacklight < Metadata
3
+
4
+ ##
5
+ # Returns a string of JSON from a GeoBlacklight hash
6
+ # @return (String)
7
+ def to_json
8
+ to_hash.to_json
9
+ end
10
+
11
+ ##
12
+ # Returns a hash from a GeoBlacklight object
13
+ # @return (Hash)
14
+ def to_hash
15
+ hash = {}
16
+ @metadata.css('field').each do |field|
17
+ (hash[field.attributes['name'].value] ||= []) << field.children.text
18
+ end
19
+ hash.collect do |key, value|
20
+ hash[key] = value.count > 1 ? { key => value } : { key => value[0] }
21
+ end
22
+ hash
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ module GeoCombine
2
+ class Iso19139 < Metadata
3
+
4
+ ##
5
+ # Returns a Nokogiri::XSLT object containing the ISO19139 to GeoBlacklight
6
+ # XSL
7
+ # @return (Nokogiri::XSLT)
8
+ def xsl
9
+ Nokogiri::XSLT(File.read('./lib/xslt/iso2geoBL.xsl'))
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module GeoCombine
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/geo_combine.rb CHANGED
@@ -1,7 +1,40 @@
1
- require 'geo_combine/version'
1
+ require 'nokogiri'
2
2
 
3
3
  module GeoCombine
4
4
 
5
+ ##
6
+ # TODO: Create a parse method that can interpret the type of metadata being
7
+ # passed in.
8
+ #
9
+ # def self.parse metadata
10
+ # end
11
+
12
+ ##
13
+ # Abstract class for GeoCombine objects
14
+ class Metadata
15
+ attr_reader :metadata
16
+
17
+ ##
18
+ # Creates a new GeoCombine::Metadata object, where metadata parameter is can
19
+ # be a File path or String of XML
20
+ # @param (String) metadata can be a File path
21
+ # "./tmp/edu.stanford.purl/bb/338/jh/0716/iso19139.xml" or a String of XML
22
+ # metadata
23
+ def initialize metadata
24
+ metadata = File.read metadata if File.readable? metadata
25
+ metadata = Nokogiri::XML(metadata) if metadata.instance_of? String
26
+ @metadata = metadata
27
+ end
28
+
29
+ ##
30
+ # Perform an XSLT tranformation on metadata using an object's XSL
31
+ def to_geoblacklight
32
+ GeoCombine::Geoblacklight.new(xsl.transform(@metadata))
33
+ end
34
+ end
5
35
  end
6
36
 
7
- load File.expand_path('../tasks/geo_combine.rake', __FILE__)
37
+ require 'geo_combine/fgdc'
38
+ require 'geo_combine/geoblacklight'
39
+ require 'geo_combine/iso19139'
40
+ require 'geo_combine/version'