Class: Mead::EadValidator
- Inherits:
-
Object
- Object
- Mead::EadValidator
- Defined in:
- lib/mead/ead_validator.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#invalid ⇒ Object
Returns the value of attribute invalid.
-
#invalid_full ⇒ Object
Returns the value of attribute invalid_full.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
-
#initialize(directory) ⇒ EadValidator
constructor
Creates a new EadValidator when given the path to a directory as a String.
- #metadata ⇒ Object
- #record_invalid(eadid, ead, error = nil) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(directory) ⇒ EadValidator
Creates a new EadValidator when given the path to a directory as a String
6 7 8 9 10 11 |
# File 'lib/mead/ead_validator.rb', line 6 def initialize(directory) @directory = directory @valid = [] @invalid = [] @invalid_full = [] end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
3 4 5 |
# File 'lib/mead/ead_validator.rb', line 3 def directory @directory end |
#invalid ⇒ Object
Returns the value of attribute invalid.
3 4 5 |
# File 'lib/mead/ead_validator.rb', line 3 def invalid @invalid end |
#invalid_full ⇒ Object
Returns the value of attribute invalid_full.
3 4 5 |
# File 'lib/mead/ead_validator.rb', line 3 def invalid_full @invalid_full end |
#valid ⇒ Object
Returns the value of attribute valid.
3 4 5 |
# File 'lib/mead/ead_validator.rb', line 3 def valid @valid end |
Instance Method Details
#metadata ⇒ Object
41 42 43 |
# File 'lib/mead/ead_validator.rb', line 41 def {:valid => @valid.sort, :invalid => @invalid.sort} end |
#record_invalid(eadid, ead, error = nil) ⇒ Object
36 37 38 39 |
# File 'lib/mead/ead_validator.rb', line 36 def record_invalid(eadid, ead, error=nil) @invalid << eadid @invalid_full << {:eadid => eadid, :error => error, :dups => ead.dups, :containers => ead.invalid} end |
#validate! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mead/ead_validator.rb', line 13 def validate! files = Dir.glob(File.join(@directory, '*.xml')).sort threads = [] files.map do |path| threads << Thread.new(path) do |path_t| eadid = File.basename(path_t, '.xml') begin ead = Mead::Ead.new({:file => File.open(path_t), :eadid => eadid}) rescue => e record_invalid(eadid, ead, e) next end if ead.valid? @valid << eadid else record_invalid(eadid, ead) end end end threads.each { |thread| thread.join } end |