Class: ActiveCMIS::Rendition
- Inherits:
-
Object
- Object
- ActiveCMIS::Rendition
- Defined in:
- lib/active_cmis/rendition.rb
Instance Attribute Summary collapse
-
#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_file(file_name) ⇒ Hash
Returns a hash with the name of the file to which was written, the lenthe, and the content type.
-
#initialize(repository, 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, link) ⇒ Rendition
Returns a new instance of Rendition.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_cmis/rendition.rb', line 13 def initialize(repository, link) @repository = repository @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
#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_file(file_name) ⇒ Hash
Returns a hash with the name of the file to which was written, the lenthe, and the content type
WARNING: this loads the complete file in memory and dumps it at once, this should be fixed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_cmis/rendition.rb', line 44 def get_file(file_name) if @url response = repository.conn.get_response(@url) status = response.code.to_i if 200 <= status && status < 300 data = response.body else raise HTTPError.new("Problem downloading rendition: status: #{status}, message: #{response.body}") end content_type = response.content_type content_lenth = response.content_length || response.body.length # In case content encoding is chunked? ?? else data = @data content_type = @format content_length = @data.length end File.open(file_name, "w") {|f| f.syswrite data } {:file => file_name, :content_type => content_type, :content_length => content_length} end |
#primary? ⇒ Boolean
Used to differentiate between rendition and primary content
35 36 37 |
# File 'lib/active_cmis/rendition.rb', line 35 def primary? @rel.nil? end |
#rendition? ⇒ Boolean
Used to differentiate between rendition and primary content
31 32 33 |
# File 'lib/active_cmis/rendition.rb', line 31 def rendition? @rel == "alternate" end |