Class RCAP::CAP_1_1::Resource

  1. lib/rcap/cap_1_1/resource.rb
Parent: Object

A Resource object is valid if

  • it has a resource description

Methods

public class

  1. new

public instance

  1. deref_uri=
  2. dereference_uri!
  3. size_in_kb
  4. to_s

Included modules

  1. Validation

Attributes

deref_uri [R] Dereferenced URI - contents of URI Base64 encoded
digest [RW] SHA-1 hash of contents of resource
mime_type [RW]
resource_desc [RW] Resource Description
size [RW] Expressed in bytes
uri [RW] Resource location

Public class methods

new ( attributes = {} )
[show source]
# File lib/rcap/cap_1_1/resource.rb, line 39
      def initialize( attributes = {} )
        @mime_type     = attributes[ :mime_type ]
        @size          = attributes[ :size ]
        @uri           = attributes[ :uri ]
        @deref_uri     = attributes[ :deref_uri ]
        @digest        = attributes[ :digest ]
        @resource_desc = attributes[ :resource_desc ]
      end

Public instance methods

deref_uri= ( value )

Sets the deref_uri. The SHA digest and size are also calculated and set.

[show source]
# File lib/rcap/cap_1_1/resource.rb, line 81
      def deref_uri=( value )
        @deref_uri = value
        self.digest = Digest::SHA1.hexdigest( @deref_uri )
        self.size = @deref_uri.bytesize
      end
dereference_uri! ()

Retrieves the content at uri and stores it in deref_uri as Base64 encoded text. It will also calculate the digest on the encoded data using SHA1 and set the size.

This uses the open-uri Ruby API to open and read the content.

[show source]
# File lib/rcap/cap_1_1/resource.rb, line 92
      def dereference_uri!
        content = URI.parse( self.uri ).read
        self.deref_uri = Base64.encode64( content )
      end
size_in_kb ()

If size is defined returns the size in kilobytes

[show source]
# File lib/rcap/cap_1_1/resource.rb, line 60
      def size_in_kb
        if self.size
          self.size.to_f/1024
        end
      end
to_s ()

Returns a string representation of the resource of the form

resource_desc
[show source]
# File lib/rcap/cap_1_1/resource.rb, line 76
      def to_s
        self.resource_desc
      end