Class: MotionAL::Assets

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

Overview

A collection of assets in the group. Assets has to belong to the group.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group) ⇒ Assets

Returns a new instance of Assets.

Parameters:



12
13
14
# File 'lib/motional/assets.rb', line 12

def initialize(group)
  @group = group
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



9
10
11
# File 'lib/motional/assets.rb', line 9

def group
  @group
end

Instance Method Details

#count(filter = :all) ⇒ Fixnum

Returns Count of assets in the group.

Examples:

group.assets.count
group.assets.count(:photo)

Parameters:

  • filter (Symbol) (defaults to: :all)

    :all(default), :photo or :video

Returns:

  • (Fixnum)

    Count of assets in the group.



78
79
80
81
82
83
84
# File 'lib/motional/assets.rb', line 78

def count(filter = :all)
  AssetsFilter.set(@group, filter)
  filtered_count = @group.al_asset_group.numberOfAssets
  AssetsFilter.reset(@group)

  filtered_count
end

#create(source, metadata = nil) {|asset, error| ... } ⇒ nil

Create an asset and add it to the group.

Examples:

group.assets.create(data, meta) do |asset, error|
  # asynchronous if a block given
  p asset.url.absoluteString
end

group.assets.create(data, meta)

Parameters:

  • source (CGImage, NSData, NSURL)

    CGImage and NSData for the photo, NSURL for the video.

  • metadata (Hash) (defaults to: nil)

    Metadata for the photo.

Yields:

  • (asset, error)

Yield Parameters:

Returns:

  • (nil)


33
34
35
36
37
38
39
40
41
42
# File 'lib/motional/assets.rb', line 33

def create(source,  = nil, &block)
  Asset.create(source, ) do |asset, error|
    if asset
      block.call(asset, error)
      self << asset
    else
      raise "Asset creation failed. #{error}"
    end
  end
end

#each(options = {}) {|asset, error| ... } ⇒ nil Also known as: find_all

Enumrate assets in the group.

Examples:

group.assets.each do |asset, error|
  # asynchronous
  p asset.url.absoluteString
end

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :filter (Symbol)

    :all(default), :photo or :video

  • :order (Symbol)

    :asc(default) or :desc

  • :indexset (NSIndexSet)

Yields:

  • (asset, error)

Yield Parameters:

Returns:

  • (nil)


61
62
63
64
65
66
67
68
69
# File 'lib/motional/assets.rb', line 61

def each(options = {}, &block)
  raise "MotionAL::Assets.each does not support :group option. Use MotionAL::Asset.find_all to get other group assets." if options[:group]

  options[:group] = @group

  MotionAL::Asset.find_all(options) do |asset, error|
    block.call(asset, error)
  end
end

#push(asset) ⇒ Object Also known as: <<

Add an asset to the group.

Parameters:



89
90
91
92
# File 'lib/motional/assets.rb', line 89

def push(asset)
  @group.add_asset(asset)
  self
end