Class: MotionAL::Representation

Inherits:
Object
  • Object
show all
Defined in:
lib/motional/representation.rb

Overview

A wrapper of ALRepresentation class.

An ALAssetRepresentation object encapsulates one of the representations of a given ALAsset object.
A given asset in the library may have more than one representation. For example, if a camera provides RAW and JPEG versions of an image, the resulting asset will have two representations—one for the RAW file and one for the JPEG file.

And added some convinience methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(asset, al_asset_representation) ⇒ Representation

Returns a new instance of Representation.

Parameters:

  • asset (MotionAL::Asset)

    A parent asset.

  • al_asset_representation (ALAssetRepresentation)

    An instance of ALAssetRepresentation.



17
18
19
20
# File 'lib/motional/representation.rb', line 17

def initialize(asset, al_asset_representation)
  @asset = asset
  @al_asset_representation = al_asset_representation
end

Instance Attribute Details

#al_asset_representationObject (readonly)

Returns the value of attribute al_asset_representation.



13
14
15
# File 'lib/motional/representation.rb', line 13

def al_asset_representation
  @al_asset_representation
end

#assetObject (readonly)

Returns the value of attribute asset.



13
14
15
# File 'lib/motional/representation.rb', line 13

def asset
  @asset
end

Instance Method Details

#:UTI(: UTI) ⇒ String

The representation’s :UTI

Returns:

  • (String)


98
# File 'lib/motional/representation.rb', line 98

make_wrapper_for_method(:UTI, "String")

#cg_image_with_options(options) ⇒ CGImageRef

Returns A full resolution CGImage of the representation.

Parameters:

  • options (Hash)

    described for CGImageSourceCreateWithData or CGImageSourceCreateWithURL.

Returns:

  • (CGImageRef)

    A full resolution CGImage of the representation.



40
41
42
# File 'lib/motional/representation.rb', line 40

def cg_image_with_options(options)
  @al_asset_representation.CGImageWithOptions(options)
end

#dataNSConcreteData

return a NSConcreteData(kind of NSData) object for the representation file.

support only jpeg and png.

Returns:

  • (NSConcreteData)


27
28
29
30
31
32
33
34
35
36
# File 'lib/motional/representation.rb', line 27

def data
  ui_image = UIImage.imageWithCGImage(self.cg_image)
  if self.filename =~ /.jpe?g$/i
    NSData.alloc.initWithData(UIImageJPEGRepresentation(ui_image, 0.0))
  elsif self.filename =~ /.png$/i
    NSData.alloc.initWithData(UIImagePNGRepresentation(ui_image))
  else
    nil
  end
end

#dimensionsCGSize

The representation’s dimensions

Returns:

  • (CGSize)


94
# File 'lib/motional/representation.rb', line 94

make_wrapper_for_method(:dimensions, "CGSize")

#filenameString Also known as: name

The representation’s filename

Returns:

  • (String)


95
# File 'lib/motional/representation.rb', line 95

make_wrapper_for_method(:filename, "String")

#full_resolution_imageCGImageRef? Also known as: cg_image

A CGImage of the representation.

Returns:

  • (CGImageRef)
  • (nil)

    When the representation has no CGImage.



57
58
59
# File 'lib/motional/representation.rb', line 57

def full_resolution_image
  @al_asset_representation.fullResolutionImage
end

#full_screen_imageCGImageRef?

A CGImage of the representation that is appropriate for displaying full screen.

Returns:

  • (CGImageRef)
  • (nil)

    When the representation has no CGImage.



66
67
68
# File 'lib/motional/representation.rb', line 66

def full_screen_image
  @al_asset_representation.fullScreenImage
end

#metadataHash?

Metadata of the representation.

Returns:

  • (Hash)

    A multidimensional hash.

  • (nil)

    When the representation has no metadata or incompatible metadata.



74
75
76
# File 'lib/motional/representation.rb', line 74

def 
  @al_asset_representation.
end

#orientationSymbol

The orientation of the representation.

Returns:

  • (Symbol)

    :up, :down :left, :right, :up_mirrored, :down_mirrored, :left_mirrored or :right_mirrored

See Also:



49
50
51
# File 'lib/motional/representation.rb', line 49

def orientation
  MotionAL.asset_orientations.key(@al_asset.valueForProperty(ALAssetPropertyOrientation))
end

#scaleFloat

The representation’s scale

Returns:

  • (Float)


93
# File 'lib/motional/representation.rb', line 93

make_wrapper_for_method(:scale, "Float")

#sizeFixnum

The representation’s size

Returns:

  • (Fixnum)


96
# File 'lib/motional/representation.rb', line 96

make_wrapper_for_method(:size, "Fixnum")

#urlNSURL

The representation’s url

Returns:

  • (NSURL)


97
# File 'lib/motional/representation.rb', line 97

make_wrapper_for_method(:url, "NSURL")