hydra-file_characterization 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81aa30a5af29b1bb419e67d30f0273faa4f7cd1a
|
4
|
+
data.tar.gz: 998e940542884ba96698b9bb4e03e8c06e9cabbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df13ebfc40df2ac4a9c6a8fac0319f1049459fbb65e47309738e6dbf0abf99a6e3641b31b5d6801cb55f33e14ae96f962d9bcd3f9d90f24719dcf0a5d6914246
|
7
|
+
data.tar.gz: e7466aa4a460b3e7ac62a06b21864ab7e4487fb23b46e99b4a11f34fc1dbf38d820e2745ba9656deb449f329378b6ab2e05ffff0eb17bd6ccc6e4ce04e65d04b
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# hydra-file_chracterization
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/hydra-file_characterization.png)](http://badge.fury.io/rb/hydra-file_characterization)
|
4
|
+
|
3
5
|
Hydra::FileCharacterization as (extracted from Sufia and Hydra::Derivatives)
|
4
6
|
|
5
7
|
## Purpose
|
@@ -29,7 +31,7 @@ xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.
|
|
29
31
|
end
|
30
32
|
```
|
31
33
|
|
32
|
-
…or even make the path callable
|
34
|
+
…or even make the path callable…
|
33
35
|
|
34
36
|
```ruby
|
35
37
|
xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits) do |config|
|
@@ -37,6 +39,14 @@ xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.
|
|
37
39
|
end
|
38
40
|
```
|
39
41
|
|
42
|
+
…or even create your custom characterizer on the file…
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :my_characterizer) do |config|
|
46
|
+
config[:my_characterizer] = lambda {|filename| … }
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
40
50
|
You can also call multiple characterizers at the same time.
|
41
51
|
|
42
52
|
```ruby
|
@@ -32,6 +32,11 @@ module Hydra
|
|
32
32
|
# end
|
33
33
|
#
|
34
34
|
# @example
|
35
|
+
# xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits) do |config|
|
36
|
+
# config[:fits] = lambda {|filename| … }
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# @example
|
35
40
|
# fits_xml, ffprobe_xml = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits, :ffprobe)
|
36
41
|
#
|
37
42
|
# @param [String] content - The contents of the original file
|
@@ -16,9 +16,13 @@ module Hydra::FileCharacterization
|
|
16
16
|
tool_name.to_s.gsub(/(?:^|_)([a-z])/) { $1.upcase }
|
17
17
|
end
|
18
18
|
|
19
|
-
def characterize_with(tool_name,
|
20
|
-
|
21
|
-
|
19
|
+
def characterize_with(tool_name, path_to_file, path_to_tool)
|
20
|
+
if path_to_tool.respond_to?(:call)
|
21
|
+
path_to_tool.call(path_to_file)
|
22
|
+
else
|
23
|
+
tool_obj = characterizer(tool_name).new(path_to_file, path_to_tool)
|
24
|
+
tool_obj.call
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
end
|
@@ -15,5 +15,28 @@ module Hydra::FileCharacterization
|
|
15
15
|
it { should eq(Characterizers::Ffprobe) }
|
16
16
|
end
|
17
17
|
|
18
|
+
context '.characterize_with' do
|
19
|
+
let(:tool_name) { :fits }
|
20
|
+
let(:filename) { __FILE__ }
|
21
|
+
let(:tool_path) { nil }
|
22
|
+
subject { Hydra::FileCharacterization.characterize_with(tool_name, filename, tool_path) }
|
23
|
+
|
24
|
+
context 'with callable tool_path and missing tool name' do
|
25
|
+
let(:tool_path) { lambda {|filename| [filename, :tool_path]} }
|
26
|
+
let(:tool_name) { :chunky_salsa }
|
27
|
+
it { should eq [filename, :tool_path] }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with missing tool name and non-callable tool_path' do
|
31
|
+
let(:tool_name) { :chunky_salsa }
|
32
|
+
let(:tool_path) { '/path' }
|
33
|
+
it 'should raise exception' do
|
34
|
+
expect {
|
35
|
+
subject
|
36
|
+
}.to raise_error(ToolNotFoundError)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
18
41
|
end
|
19
|
-
end
|
42
|
+
end
|