Class: MotionAL::Asset
- Inherits:
-
Object
- Object
- MotionAL::Asset
- Defined in:
- lib/motional/asset.rb
Overview
A wrapper of ALAsset class.
An ALAsset object represents a photo or a video managed by the Photo application.
Assets can have multiple representations, for example a photo which was captured in RAW and JPG. Different representations of the same asset may have different dimensions.
And added some convinience methods.
Instance Attribute Summary collapse
-
#al_asset ⇒ Object
readonly
An instance of ALAsset.
Class Method Summary collapse
-
.create(source, metadata = nil) {|asset, error| ... } ⇒ nil
Create an asset.
-
.find_all(options = {}) {|asset, error| ... } ⇒ nil
(also: each)
Find and enumerate assets by options.
-
.find_by_url(asset_url) {|asset, error| ... } ⇒ nil
Find an asset by a specified asset_url.
-
.video_compatible?(video_path_url) ⇒ Boolean
False means ALAssetLibrary cannot treat the video file.
Instance Method Summary collapse
-
#aspect_ratio_thumbnail ⇒ CGImageRef
Returns an aspect ratio thumbnail of the asset.
-
#asset_type ⇒ Symbol
The type of the asset.
-
#cg_image ⇒ CGImageRef?
The default representation’s cg_image.
-
#data ⇒ NSConcreteData?
The default representation’s data.
-
#date ⇒ Time?
The asset’s date.
-
#default_representation ⇒ MotionAL::Representation
(also: #rep, #file, #representation)
The default representation of the asset.
-
#dimensions ⇒ CGSize?
The default representation’s dimensions.
-
#duration ⇒ Float?
The asset’s duration.
-
#editable? ⇒ Boolean
Return true if the app haves write access for the asset.
-
#filename ⇒ String?
The default representation’s filename.
-
#full_resolution_image ⇒ CGImageRef?
The default representation’s full_resolution_image.
-
#full_screen_image ⇒ CGImageRef?
The default representation’s full_screen_image.
-
#initialize(al_asset) ⇒ Asset
constructor
A new instance of Asset.
-
#location ⇒ CLLocation?
The asset’s location.
-
#metadata ⇒ Hash?
The default representation’s metadata.
-
#orientation ⇒ Symbol
The orientation of the asset.
-
#original_asset ⇒ MotionAL::Asset?
The original version of the asset.
-
#representation_urls ⇒ Array?
The asset’s representation_urls.
-
#representation_utis ⇒ Array?
The asset’s representation_utis.
-
#representations ⇒ MotionAL::Representations
(also: #reps, #files)
The collection of representations in the asset.
-
#save_new(source, metadata = nil) {|asset, error| ... } ⇒ nil
Create a new asset forked by the asset.
-
#scale ⇒ Float?
The default representation’s scale.
-
#size ⇒ Fixnum?
The default representation’s size.
-
#thumbnail ⇒ CGImageRef
Returns a thumbnail of the asset.
-
#update(source, metadata = nil) {|asset, error| ... } ⇒ nil
Update the asset.
-
#url ⇒ NSURL?
The asset’s url.
Constructor Details
#initialize(al_asset) ⇒ Asset
17 18 19 |
# File 'lib/motional/asset.rb', line 17 def initialize(al_asset) @al_asset = al_asset end |
Instance Attribute Details
#al_asset ⇒ Object (readonly)
An instance of ALAsset.
14 15 16 |
# File 'lib/motional/asset.rb', line 14 def al_asset @al_asset end |
Class Method Details
.create(source, metadata = nil) {|asset, error| ... } ⇒ nil
use ‘MotionAL::Asset.video_compatible?(video_path_url)` before creating video.
Create an asset.
51 52 53 54 55 56 57 58 59 |
# File 'lib/motional/asset.rb', line 51 def self.create(source, = nil, &block) if source.kind_of?(NSData) self.create_by_image_data(source, , block) elsif source.kind_of?(NSURL) self.create_by_video_path(source, block) else self.create_by_cg_image(source, , block) end end |
.find_all(options = {}) {|asset, error| ... } ⇒ nil Also known as: each
Find and enumerate assets by options.
109 110 111 |
# File 'lib/motional/asset.rb', line 109 def self.find_all( = {}, &block) self.origin_find_all(, block) end |
.find_by_url(asset_url) {|asset, error| ... } ⇒ nil
Find an asset by a specified asset_url.
75 76 77 78 |
# File 'lib/motional/asset.rb', line 75 def self.find_by_url(asset_url, &block) url = asset_url.is_a?(String) ? NSURL.alloc.initWithString(asset_url) : asset_url self.origin_find_by_url(url, block) end |
.video_compatible?(video_path_url) ⇒ Boolean
117 118 119 |
# File 'lib/motional/asset.rb', line 117 def self.video_compatible?(video_path_url) MotionAL.library.al_asset_library.videoAtPathIsCompatibleWithSavedPhotosAlbum(video_path_url) end |
Instance Method Details
#aspect_ratio_thumbnail ⇒ CGImageRef
128 129 130 |
# File 'lib/motional/asset.rb', line 128 def aspect_ratio_thumbnail self.al_asset.aspectRatioThumbnail end |
#asset_type ⇒ Symbol
The type of the asset.
186 187 188 |
# File 'lib/motional/asset.rb', line 186 def asset_type MotionAL.asset_types.key(@al_asset.valueForProperty(ALAssetPropertyType)) end |
#cg_image ⇒ CGImageRef?
The default representation’s cg_image
215 |
# File 'lib/motional/asset.rb', line 215 make_wrapper_for_representation_method(:cg_image, "CGImageRef") |
#data ⇒ NSConcreteData?
The default representation’s data
214 |
# File 'lib/motional/asset.rb', line 214 make_wrapper_for_representation_method(:data, "NSConcreteData") |
#date ⇒ Time?
The asset’s date
175 |
# File 'lib/motional/asset.rb', line 175 make_wrapper_for_property(:date, ALAssetPropertyDate, "Time") |
#default_representation ⇒ MotionAL::Representation Also known as: rep, file, representation
152 153 154 |
# File 'lib/motional/asset.rb', line 152 def default_representation @default_representation ||= Representation.new(@asset, @al_asset.defaultRepresentation) end |
#dimensions ⇒ CGSize?
The default representation’s dimensions
216 |
# File 'lib/motional/asset.rb', line 216 make_wrapper_for_representation_method(:dimensions, "CGSize") |
#duration ⇒ Float?
The asset’s duration
174 |
# File 'lib/motional/asset.rb', line 174 make_wrapper_for_property(:duration, ALAssetPropertyDuration, "Float") |
#editable? ⇒ Boolean
Return true if the app haves write access for the asset. In other words true means the app can call ‘#update` for the asset.
136 137 138 |
# File 'lib/motional/asset.rb', line 136 def editable? @al_asset.editable? end |
#filename ⇒ String?
The default representation’s filename
217 |
# File 'lib/motional/asset.rb', line 217 make_wrapper_for_representation_method(:filename, "String") |
#full_resolution_image ⇒ CGImageRef?
The default representation’s full_resolution_image
211 |
# File 'lib/motional/asset.rb', line 211 make_wrapper_for_representation_method(:full_resolution_image, "CGImageRef") |
#full_screen_image ⇒ CGImageRef?
The default representation’s full_screen_image
212 |
# File 'lib/motional/asset.rb', line 212 make_wrapper_for_representation_method(:full_screen_image, "CGImageRef") |
#location ⇒ CLLocation?
The asset’s location
173 |
# File 'lib/motional/asset.rb', line 173 make_wrapper_for_property(:location, ALAssetPropertyLocation, "CLLocation") |
#metadata ⇒ Hash?
The default representation’s metadata
219 |
# File 'lib/motional/asset.rb', line 219 make_wrapper_for_representation_method(:metadata, "Hash") |
#orientation ⇒ Symbol
The orientation of the asset.
193 194 195 |
# File 'lib/motional/asset.rb', line 193 def orientation MotionAL.asset_orientations.key(@al_asset.valueForProperty(ALAssetPropertyOrientation)) end |
#original_asset ⇒ MotionAL::Asset?
The original asset was set when the asset was created by ‘#save_new`
The original version of the asset.
146 147 148 149 |
# File 'lib/motional/asset.rb', line 146 def original_asset original_al_asset = @al_asset.originalAsset Asset.new(original_al_asset) if original_al_asset end |
#representation_urls ⇒ Array?
The asset’s representation_urls
178 |
# File 'lib/motional/asset.rb', line 178 make_wrapper_for_property(:representation_urls, ALAssetPropertyURLs, "Array") |
#representation_utis ⇒ Array?
The asset’s representation_utis
177 |
# File 'lib/motional/asset.rb', line 177 make_wrapper_for_property(:representation_utis, ALAssetPropertyRepresentations, "Array") |
#representations ⇒ MotionAL::Representations Also known as: reps, files
22 23 24 |
# File 'lib/motional/asset.rb', line 22 def representations @representations ||= Representations.new(self) end |
#save_new(source, metadata = nil) {|asset, error| ... } ⇒ nil
use ‘MotionAL::Asset.video_compatible?(video_path_url)` before creating video.
Create a new asset forked by the asset.
241 242 243 |
# File 'lib/motional/asset.rb', line 241 def save_new(source, = nil, &block) origin_save_new(source, , block) end |
#scale ⇒ Float?
The default representation’s scale
213 |
# File 'lib/motional/asset.rb', line 213 make_wrapper_for_representation_method(:scale, "Float") |
#size ⇒ Fixnum?
The default representation’s size
218 |
# File 'lib/motional/asset.rb', line 218 make_wrapper_for_representation_method(:size, "Fixnum") |
#thumbnail ⇒ CGImageRef
123 124 125 |
# File 'lib/motional/asset.rb', line 123 def thumbnail self.al_asset.thumbnail end |
#update(source, metadata = nil) {|asset, error| ... } ⇒ nil
use ‘MotionAL::Asset.video_compatible?(video_path_url)` before updating video.
Update the asset. In other words replacing the asset’s representation.
265 266 267 |
# File 'lib/motional/asset.rb', line 265 def update(source, = nil, &block) origin_update(source, , block) end |
#url ⇒ NSURL?
The asset’s url
176 |
# File 'lib/motional/asset.rb', line 176 make_wrapper_for_property(:url, ALAssetPropertyAssetURL, "NSURL") |