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_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, 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_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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/active_cmis/rendition.rb', line 57 def get_data 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_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
44 45 46 47 48 |
# File 'lib/active_cmis/rendition.rb', line 44 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
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 |