Class: Archivist::Model::Document
- Inherits:
-
Object
- Object
- Archivist::Model::Document
show all
- Includes:
- Client::Constants
- Defined in:
- lib/archivist/models/document.rb
Constant Summary
collapse
- UnsupportedFormat =
Class.new(StandardError)
Client::Constants::DEFAULT_CONNECTION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Document.
23
24
25
|
# File 'lib/archivist/models/document.rb', line 23
def initialize
@conn = DEFAULT_CONNECTION
end
|
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
15
16
17
|
# File 'lib/archivist/models/document.rb', line 15
def conn
@conn
end
|
Instance Method Details
#download(format = :text) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/archivist/models/document.rb', line 35
def download(format=:text)
file_format = format_index.send(:"#{format}_format")
if file_format.nil?
raise UnsupportedFormat, "#{identifier} not available in format #{format}"
else
@conn.get(download_path(file_format.name)).
body.force_encoding('UTF-8')
end
end
|
#download_path(file) ⇒ Object
47
48
49
|
# File 'lib/archivist/models/document.rb', line 47
def download_path(file)
"/download/#{identifier}/#{file}"
end
|
27
28
29
30
31
32
33
|
# File 'lib/archivist/models/document.rb', line 27
def format_index
response = @conn.get(index_xml_path)
Model::FormatIndex.new.tap do |idx|
rep = Representation::FormatIndex.new(idx)
rep.from_xml(response.body)
end
end
|
#index_xml_path ⇒ Object
51
52
53
|
# File 'lib/archivist/models/document.rb', line 51
def index_xml_path
download_path("#{identifier}_files.xml")
end
|