dpn-bagit 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 2.2.1
4
+ - 2.2.5
5
+ - 2.3.1
6
+
7
+ script: rake test
8
+
9
+
10
+ addons:
11
+ code_climate:
12
+ repo_token: d20107af76061a5ccc8a26570c7eab36d3771f7e5d304ae4e6bc4a0aaa7a5cb4
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in dpn-bagit.gemspec
4
4
  gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
7
+
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+
2
+ [![Build Status](https://travis-ci.org/dpn-admin/dpn-bagit.svg?branch=master)](https://travis-ci.org/dpn-admin/dpn-bagit) [![Code Climate](https://codeclimate.com/github/dpn-admin/dpn-bagit/badges/gpa.svg)](https://codeclimate.com/github/dpn-admin/dpn-bagit) [![Test Coverage](https://codeclimate.com/github/dpn-admin/dpn-bagit/badges/coverage.svg)](https://codeclimate.com/github/dpn-admin/dpn-bagit/coverage)
3
+
1
4
  # DPN::Bagit
2
5
 
3
6
  ## Description
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require "dpn/bagit"
5
+ require "optparse"
6
+
7
+ options = {}
8
+ opt_parser = OptionParser.new do |opt|
9
+ opt.banner = "Usage: dpn-bagit-validator DIRECTORY"
10
+ opt.on "-l", "--location=PATH",
11
+ "Path to the volume's directory." do |location|
12
+ options[:location] = location
13
+ end
14
+ opt.on_tail("-h", "--help", "Show this message") do
15
+ puts opt
16
+ exit
17
+ end
18
+ end
19
+
20
+ opt_parser.parse!
21
+
22
+ raise ArgumentError unless options[:location]
23
+
24
+
25
+
26
+ bag = DPN::Bagit::Bag.new(options[:location])
27
+ if bag.valid?
28
+ puts "Bag is valid."
29
+ else
30
+ puts "Bag is invalid."
31
+ puts ""
32
+ puts bag.errors
33
+ end
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.8"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "test-unit"
24
+ spec.add_development_dependency "yard", "~> 0.8"
25
+ spec.add_development_dependency "simplecov"
24
26
 
25
27
  spec.add_runtime_dependency "configliere"
26
28
  spec.add_runtime_dependency "bagit", "~>0.3.2"
@@ -20,11 +20,8 @@ class DPN::Bagit::Bag
20
20
  @dpnObjectID = nil
21
21
 
22
22
  @dpnInfo = DPNInfoTxt.new(self.dpn_info_file_location())
23
- if @dpnInfo[:dpnObjectID] == nil
24
- @dpnObjectID = File.basename(_location)
25
- else
26
- @dpnObjectID = @dpnInfo[:dpnObjectID]
27
- end
23
+ @dpnObjectID = @dpnInfo[:dpnObjectID]
24
+ @dpnObjectID ||= File.basename(_location)
28
25
  end
29
26
 
30
27
 
@@ -5,86 +5,123 @@ class DPN::Bagit::Bag
5
5
  # changes made to the underlying txt file; in that case, a new Bag should be created.
6
6
  # @private
7
7
  class DPNInfoTxt
8
- private
9
- def initialize(fileLocation)
10
- @settings = DPN::Bagit::Settings.instance.config
11
- @dpnInfoKeysArrays = @settings[:bag][:dpn_info][:arrays]
12
- @dpnInfoKeysNonArrays = @settings[:bag][:dpn_info][:non_arrays]
13
- @dpnInfoErrors = []
14
- @dpnInfo = {}
15
- self.validate!(fileLocation)
8
+
9
+ # @overload initialize(file_location)
10
+ # Build a DPNInfoText from an existing dpn-info.txt file.
11
+ # @param [String] file_location The location of the existing dpn-info.txt.
12
+ # @overload initialize(opts)
13
+ # Build a DPNInfoText from scratch by supplying an options hash.
14
+ # @param [Hash] opts
15
+ # @option opts [String] :dpnObjectID
16
+ # @option opts [String] :localName
17
+ # @option opts [String] :ingestNodeName
18
+ # @option opts [String] :ingestNodeAddress
19
+ # @option opts [String] :ingestNodeContactName
20
+ # @option opts [String] :ingestNodeContactEmail
21
+ # @option opts [Fixnum] :version
22
+ # @option opts [String] :firstVersionObjectID
23
+ # @option opts [String] :bagTypeName
24
+ # @option opts [Array<String>] :interpretiveObjectIDs
25
+ # @option opts [Array<String>] :rightsObjectIDs
26
+ def initialize(opts)
27
+ @settings = DPN::Bagit::Settings.instance.config
28
+ @dpnInfoKeysArrays = @settings[:bag][:dpn_info][:arrays]
29
+ @dpnInfoKeysNonArrays = @settings[:bag][:dpn_info][:non_arrays]
30
+ @dpnInfoErrors = []
31
+ @dpnInfo = {}
32
+ if opts.is_a? String
33
+ self.from_existing(opts)
34
+ else
35
+ self.build(opts)
16
36
  end
37
+ end
38
+
39
+
40
+ # Check for validity
41
+ # @return [Boolean]
42
+ def valid?
43
+ return @dpnInfoErrors.empty?
44
+ end
45
+
46
+
47
+ # Returns a list of any errors encountered on creation and validation.
48
+ # @return [Array<String]
49
+ def getErrors()
50
+ return @dpnInfoErrors
51
+ end
52
+
53
+
54
+ # Get the value associated with the given field.
55
+ # @param key [Symbol]
56
+ def [](key)
57
+ return @dpnInfo[key.to_sym]
58
+ end
17
59
 
18
60
  protected
19
- def validate!(fileLocation)
20
- @dpnInfoKeysArrays.each do |key|
21
- @dpnInfo[key.to_sym] = []
22
- end
23
61
 
24
- if File.exists?(fileLocation)
25
- if File.readable?(fileLocation)
26
- contents = nil
27
- File.open(fileLocation, 'r') do |file|
28
- contents = file.read
29
- end
62
+ def build(opts)
63
+ (@dpnInfoKeysNonArrays + @dpnInfoKeysArrays).each do |key|
64
+ key = key.to_sym
65
+ @dpnInfo[key] = opts[key]
66
+ end
67
+ end
30
68
 
31
- @dpnInfoKeysNonArrays.each do |key|
32
- key = key.to_sym #does nothing if settings correctly configured
33
- pattern = @settings[:bag][:dpn_info][key][:regex] + @settings[:bag][:dpn_info][:capture]
34
- regex = Regexp.new(pattern)
35
- match = regex.match(contents)
36
- if match == nil or match[1] == nil
37
- @dpnInfoErrors.push("dpn-info.txt does not have the tag #{@settings[:bag][:dpn_info][key][:name]}")
38
- else
39
- @dpnInfo[key] = match[1]
40
- end
41
69
 
42
- if @dpnInfo[key].respond_to?(:strip!)
43
- @dpnInfo[key].strip!
44
- @dpnInfo[key].downcase!
45
- end
70
+ def from_existing(file_location)
71
+ @dpnInfoKeysArrays.each do |key|
72
+ @dpnInfo[key.to_sym] = []
73
+ end
74
+
75
+ if File.exists?(file_location)
76
+ if File.readable?(file_location)
77
+ contents = File.read(file_location)
46
78
 
79
+ @dpnInfoKeysNonArrays.each do |key|
80
+ key = key.to_sym #does nothing if settings correctly configured
81
+ pattern = @settings[:bag][:dpn_info][key][:regex] + @settings[:bag][:dpn_info][:capture]
82
+ regex = Regexp.new(pattern)
83
+ match = regex.match(contents)
84
+ if match == nil or match[1] == nil
85
+ @dpnInfoErrors.push("dpn-info.txt does not have the tag #{@settings[:bag][:dpn_info][key][:name]}")
86
+ else
87
+ @dpnInfo[key] = match[1]
47
88
  end
48
89
 
49
- @dpnInfoKeysArrays.each do |key|
50
- key = key.to_sym #does nothing if settings correctly configured
51
- pattern = @settings[:bag][:dpn_info][key][:regex] + @settings[:bag][:dpn_info][:capture]
52
- regex = Regexp.new(pattern)
53
- if regex.match(contents) == nil
54
- @dpnInfoErrors.push("dpn-info.txt does not have the tag #{@settings[:bag][:dpn_info][key][:name]}")
55
- @dpnInfo[key] = []
56
- else
57
- @dpnInfo[key] = contents.scan(regex)
58
- @dpnInfo[key].flatten!
59
- @dpnInfo[key].each_index do |i|
60
- @dpnInfo[key][i].strip!
61
- @dpnInfo[key][i].downcase!
62
- if @dpnInfo[key][i] == ''
63
- @dpnInfo[key].delete_at(i)
64
- end
90
+ if @dpnInfo[key].respond_to?(:strip!)
91
+ @dpnInfo[key].strip!
92
+ @dpnInfo[key].downcase!
93
+ end
94
+
95
+ end
96
+
97
+ @dpnInfoKeysArrays.each do |key|
98
+ key = key.to_sym #does nothing if settings correctly configured
99
+ pattern = @settings[:bag][:dpn_info][key][:regex] + @settings[:bag][:dpn_info][:capture]
100
+ regex = Regexp.new(pattern)
101
+ if regex.match(contents) == nil
102
+ @dpnInfoErrors.push("dpn-info.txt does not have the tag #{@settings[:bag][:dpn_info][key][:name]}")
103
+ @dpnInfo[key] = []
104
+ else
105
+ @dpnInfo[key] = contents.scan(regex)
106
+ @dpnInfo[key].flatten!
107
+ @dpnInfo[key].each_index do |i|
108
+ @dpnInfo[key][i].strip!
109
+ @dpnInfo[key][i].downcase!
110
+ if @dpnInfo[key][i] == ''
111
+ @dpnInfo[key].delete_at(i)
65
112
  end
66
113
  end
67
114
  end
68
- else
69
- @dpnInfoErrors.push("dpn-info.txt exists, but cannot be opened for reading.")
70
115
  end
71
-
72
116
  else
73
- @dpnInfoErrors.push("dpn-info.txt cannot be found.")
117
+ @dpnInfoErrors.push("dpn-info.txt exists, but cannot be opened for reading.")
74
118
  end
75
- end
76
119
 
77
- public
78
- # Returns a list of any errors encountered on creation and validation.
79
- # @return [Array<String]
80
- def getErrors()
81
- return @dpnInfoErrors
120
+ else
121
+ @dpnInfoErrors.push("dpn-info.txt cannot be found.")
82
122
  end
123
+ end
124
+
83
125
 
84
- # Get the value associated with the given field.
85
- # @param key [Symbol]
86
- def [](key)
87
- return @dpnInfo[key.to_sym]
88
- end
89
126
  end
90
127
  end
@@ -1,2 +1,3 @@
1
+ require "bagit"
1
2
  require "dpn/bagit/ext/bagit/bag"
2
3
  require "dpn/bagit/ext/bagit/valid"
@@ -1,9 +1,11 @@
1
+ require "bundler/setup"
1
2
  require "configliere"
2
- require "bundler"
3
+ require "singleton"
4
+
3
5
 
4
6
  # A class that manages the various settings required by dpn-bagit.
5
7
  class DPN::Bagit::Settings
6
- include Singleton
8
+ include ::Singleton
7
9
 
8
10
  def initialize
9
11
  @config = nil
@@ -1,5 +1,5 @@
1
1
  module DPN
2
2
  module Bagit
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dpn-bagit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Hockey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-22 00:00:00.000000000 Z
11
+ date: 2016-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: configliere
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -87,13 +115,16 @@ executables: []
87
115
  extensions: []
88
116
  extra_rdoc_files: []
89
117
  files:
118
+ - ".codeclimate.yml"
90
119
  - ".gitignore"
91
120
  - ".rspec"
121
+ - ".rubocop.yml"
92
122
  - ".travis.yml"
93
123
  - Gemfile
94
124
  - LICENSE.txt
95
125
  - README.md
96
126
  - Rakefile
127
+ - bin/dpn-bagit-validator
97
128
  - dpn-bagit.gemspec
98
129
  - lib/dpn/bagit.rb
99
130
  - lib/dpn/bagit/bag.rb
@@ -126,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
157
  version: '0'
127
158
  requirements: []
128
159
  rubyforge_project:
129
- rubygems_version: 2.4.5
160
+ rubygems_version: 2.4.5.1
130
161
  signing_key:
131
162
  specification_version: 4
132
163
  summary: An implementation of the DPN Bagit spec.