Class: Mrt::Ingest::Component
- Inherits:
-
Object
- Object
- Mrt::Ingest::Component
- Defined in:
- lib/mrt/ingest/component.rb
Overview
Represents a component of an object to ingest. Either a #URI or a #File.
Instance Attribute Summary collapse
-
#server ⇒ Object
readonly
:nodoc:.
-
#uri ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
Instance Method Summary collapse
- #digest_type ⇒ Object
- #digest_value ⇒ Object
-
#initialize(server, location, options) ⇒ Component
constructor
A new instance of Component.
- #to_manifest_entry ⇒ Object
Constructor Details
#initialize(server, location, options) ⇒ Component
Returns a new instance of Component.
11 12 13 14 15 16 17 18 19 |
# File 'lib/mrt/ingest/component.rb', line 11 def initialize(server, location, ) @server = server @name = [:name] @digest = [:digest] @mime_type = [:mime_type] @size = [:size] init_uri(location) end |
Instance Attribute Details
#server ⇒ Object (readonly)
:nodoc:
9 10 11 |
# File 'lib/mrt/ingest/component.rb', line 9 def server @server end |
#uri ⇒ Object (readonly)
:nodoc:
9 10 11 |
# File 'lib/mrt/ingest/component.rb', line 9 def uri @uri end |
Class Method Details
.from_erc(server, erc) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/mrt/ingest/component.rb', line 22 def from_erc(server, erc) return Component.new(server, erc, name: 'mrt-erc.txt') if erc.is_a?(URI) || erc.is_a?(File) return from_hash(server, erc) if erc.is_a?(Hash) raise ArgumentError, 'Bad ERC supplied: must be a URI, File, or Hash' end |
.from_hash(server, erc_h) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/mrt/ingest/component.rb', line 29 def from_hash(server, erc_h) uri_str, path = server.add_file do |f| f.write("erc:\n") erc_h.each_pair { |k, v| f.write("#{k}: #{v}\n") } end digest = Mrt::Ingest::MessageDigest::MD5.from_file(File.new(path)) Component.new(server, URI.parse(uri_str), name: 'mrt-erc.txt', digest: digest) end |
Instance Method Details
#digest_type ⇒ Object
44 45 46 |
# File 'lib/mrt/ingest/component.rb', line 44 def digest_type @digest && @digest.type end |
#digest_value ⇒ Object
48 49 50 |
# File 'lib/mrt/ingest/component.rb', line 48 def digest_value @digest && @digest.value end |
#to_manifest_entry ⇒ Object
40 41 42 |
# File 'lib/mrt/ingest/component.rb', line 40 def to_manifest_entry "#{@uri} | #{digest_type} | #{digest_value} | #{@size} | | #{@name} | #{@mime_type}\n" end |