Class: ActiveCMIS::Rendition
- Inherits:
-
Object
- Object
- ActiveCMIS::Rendition
- Defined in:
- lib/active_cmis/rendition.rb
Instance Attribute Summary collapse
-
#document ⇒ ActiveCMIS::Document
readonly
The document to which the rendition belongs.
-
#format ⇒ String?
readonly
The format is equal to the mime type, but may be unset or misleading.
- #rendition_kind ⇒ String? readonly
- #repository ⇒ Repository readonly
-
#size ⇒ Numeric?
readonly
Size of the rendition, may not be given or misleading.
Instance Method Summary collapse
-
#get_data ⇒ Hash
Returns a hash with the data of te rendition, the length and the content type.
-
#get_file(file_name) ⇒ Hash
Returns a hash with the name of the file to which was written, the length, and the content type.
-
#initialize(repository, document, link) ⇒ Rendition
constructor
A new instance of Rendition.
-
#primary? ⇒ Boolean
Used to differentiate between rendition and primary content.
-
#rendition? ⇒ Boolean
Used to differentiate between rendition and primary content.
Constructor Details
#initialize(repository, document, link) ⇒ Rendition
Returns a new instance of Rendition.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_cmis/rendition.rb', line 15 def initialize(repository, document, link) @repository = repository @document = document @rel = link['rel'] == "alternate" @rendition_kind = link['renditionKind'] if rendition? @format = link['type'] if link['href'] @url = URI(link['href']) else # For inline content streams @data = link['data'] end @size = link['length'] ? link['length'].to_i : nil @link = link # FIXME: For debugging purposes only, remove end |
Instance Attribute Details
#document ⇒ ActiveCMIS::Document (readonly)
Returns The document to which the rendition belongs.
12 13 14 |
# File 'lib/active_cmis/rendition.rb', line 12 def document @document end |
#format ⇒ String? (readonly)
Returns The format is equal to the mime type, but may be unset or misleading.
10 11 12 |
# File 'lib/active_cmis/rendition.rb', line 10 def format @format end |
#rendition_kind ⇒ String? (readonly)
8 9 10 |
# File 'lib/active_cmis/rendition.rb', line 8 def rendition_kind @rendition_kind end |
#repository ⇒ Repository (readonly)
4 5 6 |
# File 'lib/active_cmis/rendition.rb', line 4 def repository @repository end |
#size ⇒ Numeric? (readonly)
Returns Size of the rendition, may not be given or misleading.
6 7 8 |
# File 'lib/active_cmis/rendition.rb', line 6 def size @size end |
Instance Method Details
#get_data ⇒ Hash
Returns a hash with the data of te rendition, the length and the content type
WARNING: this loads all the data in memory Possible future enhancement could be to allow a block to which data is passed in chunks?r Not sure that is possible with Net::HTTP though.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/active_cmis/rendition.rb', line 60 def get_data if @url response = repository.conn.get_response(@url) status = response.code.to_i if 200 <= status && status < 300 data = response.body elsif 300 <= status && status < 400 location = response["location"] new_url = URI.parse(location) new_url = @url + location if new_url.relative? @url = new_url get_data else raise HTTPError.new("Problem downloading rendition: status: #{status}, message: #{response.body}") end content_type = response.content_type content_length = response.content_length || response.body.length # In case content encoding is chunked? ?? else data = @data content_type = @format content_length = @data.length end {:data => data, :content_type => content_type, :content_length => content_length} end |
#get_file(file_name) ⇒ Hash
Returns a hash with the name of the file to which was written, the length, and the content type
WARNING: this loads the complete file in memory and dumps it at once, this should be fixed
47 48 49 50 51 |
# File 'lib/active_cmis/rendition.rb', line 47 def get_file(file_name) response = get_data File.open(file_name, "w") {|f| f.syswrite response.delete(:data) } response.merge!(:file_name => file_name) end |
#primary? ⇒ Boolean
Used to differentiate between rendition and primary content
38 39 40 |
# File 'lib/active_cmis/rendition.rb', line 38 def primary? @rel.nil? end |
#rendition? ⇒ Boolean
Used to differentiate between rendition and primary content
34 35 36 |
# File 'lib/active_cmis/rendition.rb', line 34 def rendition? @rel == "alternate" end |