tastyhat-cul-fedora-arm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ private
3
+ .DS_Store
4
+ coverage
5
+ rdoc
6
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 James Stuart
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = cul-fedora-arm
2
+
3
+ This is designed, given an input specification referring to several metadata and resource files, create and ingest objects into a Fedora reposito
4
+
5
+ == Input
6
+
7
+ The input consists of a specification of relationships and metadata that can be given in one of three ways:
8
+ * A file name
9
+ * An enumerable array of strings
10
+ * A series of FILL IN objects
11
+
12
+ === Input Specification
13
+
14
+ Description goes here.
15
+
16
+ == Note on Patches/Pull Requests
17
+
18
+ * Fork the project.
19
+ * Make your feature addition or bug fix.
20
+ * Add tests for it. This is important so I don't break it in a
21
+ future version unintentionally.
22
+ * Commit, do not mess with rakefile, version, or history.
23
+ (if you want to have your own version, that is fine but
24
+ bump version in a commit by itself I can ignore when I pull)
25
+ * Send me a pull request. Bonus points for topic branches.
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2009 James Stuart. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "cul-fedora-arm"
8
+ gem.summary = %Q{Tools for dealing with Cul ARM specification}
9
+ gem.description = %Q{Tools for dealing with Cul ARM specification}
10
+ gem.email = "tastyhat@jamesstuart.org"
11
+ gem.homepage = "http://github.com/tastyhat/cul-fedora-arm"
12
+ gem.authors = ["James Stuart"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ gem.add_development_dependency "thoughtbot-factory_girl"
15
+ gem.add_dependency "activesupport"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/*_test.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ if File.exist?('VERSION')
49
+ version = File.read('VERSION')
50
+ else
51
+ version = ""
52
+ end
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "cul-fedora-arm #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cul-fedora-arm}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["James Stuart"]
12
+ s.date = %q{2009-08-26}
13
+ s.description = %q{Tools for dealing with Cul ARM specification}
14
+ s.email = %q{tastyhat@jamesstuart.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "cul-fedora-arm.gemspec",
27
+ "lib/cul-fedora-arm.rb",
28
+ "lib/cul/fedora/arm/builder.rb",
29
+ "test/cul_fedora_arm_builder_test.rb",
30
+ "test/factories.rb",
31
+ "test/factories/cul_fedora_arm_builder_factory.rb",
32
+ "test/fixtures/case1/builder-template.txt",
33
+ "test/helpers/template_builder.rb",
34
+ "test/test_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/tastyhat/cul-fedora-arm}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{Tools for dealing with Cul ARM specification}
41
+ s.test_files = [
42
+ "test/cul_fedora_arm_builder_test.rb",
43
+ "test/factories/cul_fedora_arm_builder_factory.rb",
44
+ "test/factories.rb",
45
+ "test/helpers/template_builder.rb",
46
+ "test/test_helper.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ s.add_development_dependency(%q<thoughtbot-factory_girl>, [">= 0"])
56
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
+ s.add_dependency(%q<thoughtbot-factory_girl>, [">= 0"])
60
+ s.add_dependency(%q<activesupport>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
+ s.add_dependency(%q<thoughtbot-factory_girl>, [">= 0"])
65
+ s.add_dependency(%q<activesupport>, [">= 0"])
66
+ end
67
+ end
@@ -0,0 +1,2 @@
1
+ require "cul/fedora/arm/builder"
2
+ require "activesupport"
@@ -0,0 +1,89 @@
1
+ module Cul
2
+ module Fedora
3
+ module Arm
4
+ class Builder
5
+ DEFAULT_TEMPLATE_HEADER = [:sequence, :aggregate_under, :metadata, :metadata_type, :content, :content_type, :id, :license]
6
+
7
+ REQUIRED_COLUMNS = [:sequence]
8
+ MANDATORY_COLUMNS = [:sequence, :aggregate_under, :metadata]
9
+ VALID_COLUMNS = [:sequence, :aggregate_under, :metadata, :metadata_type, :content, :content_type, :id, :license]
10
+
11
+ attr_reader :parts
12
+
13
+ def initialize(*args)
14
+ options = args.extract_options!
15
+
16
+ @parts = []
17
+
18
+
19
+ if template = options.delete(:template)
20
+ parse_template(template)
21
+ end
22
+
23
+ raise ArgumentError, "arguments should only include one of the following: :template" unless options.empty?
24
+ end
25
+
26
+
27
+ def add_part(*args)
28
+ value_hash = args.extract_options!
29
+
30
+ test_for_invalid_columns(value_hash.keys)
31
+ test_for_required_columns(value_hash)
32
+
33
+ raise "Sequence ID already taken" if part_by_sequence(value_hash[:sequence])
34
+
35
+ @parts << value_hash
36
+ end
37
+
38
+ def part_by_sequence(sequence_id)
39
+ @parts.detect { |p| p[:sequence] == sequence_id}
40
+ end
41
+
42
+ protected
43
+
44
+ def test_for_required_columns(value_hash)
45
+ missing_values = REQUIRED_COLUMNS.select { |col| !value_hash.has_key?(col) || value_hash[col].nil? }
46
+ raise "Missing required values #{missing_values.join(",")}" unless missing_values.empty?
47
+ end
48
+
49
+ def test_for_invalid_columns(columns)
50
+ invalid_columns = columns.select { |c| !VALID_COLUMNS.include?(c) }
51
+ raise "Invalid column(s) found: #{invalid_columns.join(",")}" unless invalid_columns.empty?
52
+ end
53
+
54
+ def parse_template(template)
55
+ header_columns = []
56
+ custom_header = false
57
+ template.each_with_index do |line, i|
58
+ # check for header
59
+ if i == 0
60
+ case line.to_s
61
+ when /^[0-9]/
62
+ header_columns = DEFAULT_TEMPLATE_HEADER
63
+ when /^\w/
64
+ custom_header = true
65
+ header_columns = line.split("\t").collect { |cn| cn.strip.underscore.to_sym }
66
+ raise "First column of custom designed headers must be sequence" unless header_columns[0] == :sequence
67
+ end
68
+
69
+
70
+ missing_mandatory_columns = MANDATORY_COLUMNS.select { |c| !header_columns.include?(c) }
71
+ raise "Missing mandatory column(s) found: #{missing_mandatory_columns.join(",")}" unless missing_mandatory_columns.empty?
72
+
73
+ test_for_invalid_columns(header_columns)
74
+
75
+ next if custom_header
76
+
77
+ end
78
+ value_hash = Hash[*header_columns.zip(line.split("\t").collect(&:strip)).flatten]
79
+ add_part(value_hash)
80
+ end
81
+
82
+ header_columns
83
+ end
84
+
85
+
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,128 @@
1
+ require 'test_helper'
2
+ require 'test/helpers/template_builder'
3
+
4
+
5
+ class CulFedoraArmBuilderTest < Test::Unit::TestCase
6
+
7
+ context "The builder class" do
8
+ setup do
9
+ @builder_class = Cul::Fedora::Arm::Builder
10
+ end
11
+
12
+ should "have a blank read_only array of parts" do
13
+ @builder = @builder_class.new
14
+
15
+ assert_instance_of @builder_class, @builder
16
+ assert_equal [], @builder.parts
17
+ assert_raise NoMethodError do
18
+ @builder.parts = [:test]
19
+ end
20
+ end
21
+
22
+ should "have a default array of columns for templates without headers" do
23
+ assert_equal @builder_class::DEFAULT_TEMPLATE_HEADER, [:sequence, :aggregate_under, :metadata, :metadata_type, :content, :content_type, :id, :license]
24
+ end
25
+
26
+
27
+ should "have a list of mandatory, valid, and required columns" do
28
+ assert_equal @builder_class::REQUIRED_COLUMNS, [:sequence]
29
+ assert_equal @builder_class::MANDATORY_COLUMNS, [:sequence, :aggregate_under, :metadata]
30
+ assert_equal @builder_class::VALID_COLUMNS, [:sequence, :aggregate_under, :metadata, :metadata_type, :content, :content_type, :id, :license]
31
+ end
32
+
33
+ should "accept only options :template" do
34
+ assert_raise(ArgumentError) do
35
+ @builder_class.new(:template => nil, :invalid => true)
36
+ end
37
+ end
38
+
39
+ context "given a blank builder" do
40
+ setup do
41
+ @builder = @builder_class.new
42
+ end
43
+
44
+ should "have a blank array of parts" do
45
+ assert_equal @builder.parts, []
46
+ end
47
+
48
+ should "be able to add parts" do
49
+ @builder.add_part(:sequence => "0", :aggregate_under => "collection:1;ac:5", :metadata => "/test-0001.xml")
50
+ end
51
+
52
+ should "not add parts without a sequence" do
53
+ assert_raise RuntimeError, "Missing required values sequence" do
54
+ @builder.add_part(:aggregate_under => "collection:1;ac:5", :metadata => "/test-0001.xml")
55
+ end
56
+ end
57
+
58
+ should "not add parts with the same sequence id" do
59
+
60
+ assert_raise(RuntimeError, "Sequence ID already taken") do
61
+ @builder.add_part(:sequence => "2", :metadata => "/test-0001.xml")
62
+ @builder.add_part(:sequence => "2", :metadata => "/test-0001.xml")
63
+ end
64
+ end
65
+ end
66
+
67
+ context "given headers for templates" do
68
+ setup do
69
+ @good_header = %w{sequence aggregateUnder metadata metadataType content contentType id}
70
+ @invalid_column = %w{sequence aggregateUnder metadata random}
71
+ @sequence_not_first = %w{aggregateUnder metadata sequence}
72
+ @missing_mandatory = %w{sequence aggregateUnder metadataType}
73
+ end
74
+
75
+ should "accept good headers" do
76
+ assert_instance_of @builder_class, @builder_class.new(:template => template_builder(@good_header))
77
+ end
78
+
79
+ should "accept blank template" do
80
+ assert_nothing_raised do
81
+ @builder_class.new(:template => nil)
82
+ end
83
+ end
84
+
85
+ should "insist on sequence being the first column" do
86
+ assert_raise RuntimeError, "First column of custom designed headers must be sequence" do
87
+ @builder_class.new(:template => template_builder(@sequence_not_first))
88
+ end
89
+ end
90
+
91
+ should "reject invalid column names" do
92
+ assert_raise RuntimeError, "Invalid column name: random" do
93
+ @builder_class.new(:template => template_builder(@invalid_column))
94
+ end
95
+ end
96
+
97
+ should "insist on all mandatory columns" do
98
+ assert_raise RuntimeError, "Missing mandatory column: metadata" do
99
+ @builder_class.new(:template => template_builder(@missing_mandatory))
100
+ end
101
+ end
102
+ end
103
+
104
+ context "with an example template with header" do
105
+ setup do
106
+ @builder = @builder_class.new(:template => File.open("test/fixtures/case1/builder-template.txt", "r"))
107
+ end
108
+
109
+ should "load successfully" do
110
+ assert_instance_of @builder_class, @builder
111
+ end
112
+
113
+ should "ignore the header and load template data successfully" do
114
+ assert_equal @builder.parts.length, 4
115
+ assert_equal @builder.parts[0][:metadata], "/test-0001.xml"
116
+ assert_equal @builder.parts[3][:license], "http://creativecommons.org/licenses/by-nc-nd/3.0/us/"
117
+ end
118
+
119
+ should "have parts accessible by sequence id" do
120
+ assert_kind_of Hash, @builder.part_by_sequence("5")
121
+ assert_equal @builder.parts[3], @builder.part_by_sequence("5")
122
+ end
123
+ end
124
+ end
125
+
126
+
127
+ end
128
+
data/test/factories.rb ADDED
@@ -0,0 +1 @@
1
+ require "cul-fedora-arm"
@@ -0,0 +1,3 @@
1
+ Factory.define :builder, :class => Cul::Fedora::Arm::Builder do |f|
2
+
3
+ end
@@ -0,0 +1,5 @@
1
+ sequence aggregateUnder metadata metadataType content contentType id license
2
+ 0 collection:1;ac:5 /test-0001.xml MODS ContentAggregator AC:P:5001
3
+ 1 0 /01-Northover_IPD_SovDebt_Working_Paper.pdf Resource http://creativecommons.org/licenses/by-nc-nd/3.0/us/
4
+ 4 collection:1;ac:5 /test-0002.xml MODS ContentAggregator AC:P:5002
5
+ 5 4 /02-851.pdf Resource http://creativecommons.org/licenses/by-nc-nd/3.0/us/
@@ -0,0 +1,4 @@
1
+
2
+ def template_builder(*lines_of_elements)
3
+ lines_of_elements.collect { |l| l.join("\t")}.join("\r\n")
4
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'factory_girl'
5
+ require 'activesupport'
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+
10
+ require 'cul-fedora-arm'
11
+
12
+ class ActiveSupport::TestCase
13
+ end
14
+
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tastyhat-cul-fedora-arm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Stuart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: thoughtbot-factory_girl
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: Tools for dealing with Cul ARM specification
46
+ email: tastyhat@jamesstuart.org
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - cul-fedora-arm.gemspec
62
+ - lib/cul-fedora-arm.rb
63
+ - lib/cul/fedora/arm/builder.rb
64
+ - test/cul_fedora_arm_builder_test.rb
65
+ - test/factories.rb
66
+ - test/factories/cul_fedora_arm_builder_factory.rb
67
+ - test/fixtures/case1/builder-template.txt
68
+ - test/helpers/template_builder.rb
69
+ - test/test_helper.rb
70
+ has_rdoc: false
71
+ homepage: http://github.com/tastyhat/cul-fedora-arm
72
+ licenses:
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.3.5
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Tools for dealing with Cul ARM specification
97
+ test_files:
98
+ - test/cul_fedora_arm_builder_test.rb
99
+ - test/factories/cul_fedora_arm_builder_factory.rb
100
+ - test/factories.rb
101
+ - test/helpers/template_builder.rb
102
+ - test/test_helper.rb