Class: MotionAL::Group
- Inherits:
-
Object
- Object
- MotionAL::Group
- Defined in:
- lib/motional/group.rb
Overview
A wrapper of ALAssetGroup class.
An ALAssetsGroup object represents an ordered set of the assets managed by the Photos application. The order of the elements is the same as the user sees in the Photos application. An asset can belong to multiple assets groups.
Assets groups themselves are synced via iTunes, created to hold the user’s saved photos or created during camera import. You cannot directly modify the groups using ALAssetsGroup. You can indirectly modify the Saved Photos group by saving images or videos into it using the ALAssetsLibrary class.
And added some convinience methods.
Instance Attribute Summary collapse
-
#al_asset_group ⇒ Object
readonly
An instance of ALAssetGroup.
Class Method Summary collapse
-
.create(group_name) {|group, error| ... } ⇒ nil
Create a group.
-
.find_all(options = {}) {|group, error| ... } ⇒ nil
(also: each)
Find and enumerate all groups in the AssetLibrary.
-
.find_by_name(group_name) {|group, error| ... } ⇒ nil
Find a group by a specified group name.
-
.find_by_url(group_url) {|group, error| ... } ⇒ nil
Find a group by a specified group_url.
-
.find_camera_roll {|group, error| ... } ⇒ nil
Find the Camera Roll(built-in default group).
-
.find_photo_library {|group, error| ... } ⇒ nil
Find the Photo Library(synced from iTunes).
Instance Method Summary collapse
-
#add_asset(asset) ⇒ Boolean
Add an asset to the group.
-
#asset_group_type ⇒ Symbol
The type of the group.
-
#assets ⇒ MotionAL::Assets
The collection of assets in the group.
-
#editable? ⇒ Boolean
Return true if your app has write access for the group.
-
#initialize(al_asset_group) ⇒ Group
constructor
A new instance of Group.
-
#name ⇒ String?
The gruop’s name.
-
#persistent_id ⇒ String?
The gruop’s persistent_id.
-
#poster_image ⇒ CGImageRef
The group’s poster image.
-
#url ⇒ NSURL?
The gruop’s url.
Constructor Details
#initialize(al_asset_group) ⇒ Group
Returns a new instance of Group.
17 18 19 |
# File 'lib/motional/group.rb', line 17 def initialize(al_asset_group) @al_asset_group = al_asset_group end |
Instance Attribute Details
#al_asset_group ⇒ Object (readonly)
An instance of ALAssetGroup.
14 15 16 |
# File 'lib/motional/group.rb', line 14 def al_asset_group @al_asset_group end |
Class Method Details
.create(group_name) {|group, error| ... } ⇒ nil
Create a group. A group should not be created if a specified name already exists.
38 39 40 |
# File 'lib/motional/group.rb', line 38 def self.create(group_name, &block) self.origin_create(group_name, block) end |
.find_all(options = {}) {|group, error| ... } ⇒ nil Also known as: each
group_type :all includes all groups except ‘Photo Library’
Find and enumerate all groups in the AssetLibrary.
133 134 135 |
# File 'lib/motional/group.rb', line 133 def self.find_all( = {}, &block) origin_find_all(, block) end |
.find_by_name(group_name) {|group, error| ... } ⇒ nil
It is recommended to use find_by_url instead of this. Because a group could be renamed.
Find a group by a specified group name.
76 77 78 79 80 81 |
# File 'lib/motional/group.rb', line 76 def self.find_by_name(group_name, &block) group_name = /^#{group_name}$/ if group_name.kind_of? String find_all do |group, error| block.call(group, error) if group.name =~ group_name end end |
.find_by_url(group_url) {|group, error| ... } ⇒ nil
Find a group by a specified group_url.
56 57 58 59 |
# File 'lib/motional/group.rb', line 56 def self.find_by_url(group_url, &block) url = group_url.is_a?(String) ? NSURL.alloc.initWithString(group_url) : group_url origin_find_by_url(url, block) end |
.find_camera_roll {|group, error| ... } ⇒ nil
Find the Camera Roll(built-in default group)
95 96 97 |
# File 'lib/motional/group.rb', line 95 def self.find_camera_roll(&block) find_by_name(/Camera Roll|Saved Photos/) {|group, error| block.call(group, error) } end |
.find_photo_library {|group, error| ... } ⇒ nil
Find the Photo Library(synced from iTunes)
111 112 113 |
# File 'lib/motional/group.rb', line 111 def self.find_photo_library(&block) find_all({group_type: :library}) { |group, error| block.call(group, error) } end |
Instance Method Details
#add_asset(asset) ⇒ Boolean
cannot remove ALAsset from ALAssetGroup by yor app
Add an asset to the group.
165 166 167 |
# File 'lib/motional/group.rb', line 165 def add_asset(asset) @al_asset_group.addAsset(asset.al_asset) end |
#asset_group_type ⇒ Symbol
The type of the group.
192 193 194 |
# File 'lib/motional/group.rb', line 192 def asset_group_type MotionAL.asset_group_types.key(@al_asset_group.valueForProperty(ALAssetsGroupPropertyType)) end |
#assets ⇒ MotionAL::Assets
The collection of assets in the group.
142 143 144 |
# File 'lib/motional/group.rb', line 142 def assets @assets ||= Assets.new(self) end |
#editable? ⇒ Boolean
Return true if your app has write access for the group. In other words true means your app can add assets to the group.
150 151 152 |
# File 'lib/motional/group.rb', line 150 def editable? @al_asset_group.editable? end |
#name ⇒ String?
The gruop’s name
185 |
# File 'lib/motional/group.rb', line 185 make_wrapper_for_property(:name, ALAssetsGroupPropertyName, "String") |
#persistent_id ⇒ String?
The gruop’s persistent_id
186 |
# File 'lib/motional/group.rb', line 186 make_wrapper_for_property(:persistent_id, ALAssetsGroupPropertyPersistentID, "String") |
#poster_image ⇒ CGImageRef
Returns The group’s poster image.
155 156 157 |
# File 'lib/motional/group.rb', line 155 def poster_image @al_asset_group.posterImage end |
#url ⇒ NSURL?
The gruop’s url
187 |
# File 'lib/motional/group.rb', line 187 make_wrapper_for_property(:url, ALAssetsGroupPropertyURL, "NSURL") |