Class: Aperture::PhotoSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/aperture/photo_set.rb

Overview

Overview

The PhotoSet object that contains a series of Photo objects in a hash. This object is used by the Library, Album and Project objects cotain photos. This object also contains methods to look up interest statistics across the set.

Statistic gathering methods

  • photo_count - number of photos in set

  • version_count - number of versions across all photos in set

  • camera_model_count_hash - count of how many times each camera used in the set

  • lens_model_count_hash - count of how many times each lens used in the set

Note This object can be directly treated like an array using each or any method from the Enumerable module. These will access the the values, the Photo objects, contained within the hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(photos = {}) ⇒ PhotoSet

Creates a new PhotoSet, can be passed an array of Photo objects



23
24
25
# File 'lib/aperture/photo_set.rb', line 23

def initialize(photos = {})
  @photos = photos
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

This method passes any unknown method calls onto the hash of photos, allowing you to treat the PhotoSet object as the Hash of photos it holds.



40
41
42
# File 'lib/aperture/photo_set.rb', line 40

def method_missing(sym, *args, &block)
  @photos.send(sym, *args, &block) if @photos.respond_to?(sym)
end

Instance Attribute Details

#photosObject

Returns the value of attribute photos.



20
21
22
# File 'lib/aperture/photo_set.rb', line 20

def photos
  @photos
end

Instance Method Details

#<<(photo) ⇒ Object

Adds a Photo to the hash PhotoSet uses to track Photo’s using the photo’s UUID. This UUID matches up to the masterUuid found in Version#attributes



29
30
31
# File 'lib/aperture/photo_set.rb', line 29

def <<(photo)
  @photos[ photo.master_attributes['uuid'] ] = photo
end

#camera_model_count_hashObject

Returns a hash in the following format

  • The keys are the camera model for the photo parsed from the EXIF information

  • The value is the number of times that camera model shows up across all the photos in the set



59
60
61
62
63
64
65
66
67
# File 'lib/aperture/photo_set.rb', line 59

def camera_model_count_hash
  hash = Hash.new(0)
  self.each do |photo|
    model = photo.version(1).attributes['exifProperties']['Model']
    hash[model] += 1
  end

  return hash
end

#each(&blk) ⇒ Object

Iterates over the hash’s values, ie the photos, the PhotoSet is tracking



34
35
36
# File 'lib/aperture/photo_set.rb', line 34

def each &blk
  @photos.values.each &blk
end

#find_by_keyword(keyword) ⇒ Object

Returns a new PhotoSet where the photos match the passed keyword



84
85
86
87
88
# File 'lib/aperture/photo_set.rb', line 84

def find_by_keyword(keyword)
  versions = map {|p| p.versions }.flatten
  matching = versions.select {|v| v.attributes['keywords'] && v.attributes['keywords'].include?(keyword) }
  return PhotoSet.new(matching.map{|v| v.photo}.uniq)
end

#lens_model_count_hashObject

Returns a hash in the following format

  • The keys are the lens model for the photo parsed from the EXIF information

  • The value is the number of times that lens model shows up across all the photos in the set



73
74
75
76
77
78
79
80
81
# File 'lib/aperture/photo_set.rb', line 73

def lens_model_count_hash
  hash = Hash.new(0)
  self.each do |photo|
    model = photo.version(1).attributes['exifProperties']['LensModel']
    hash[model] += 1
  end

  return hash
end

#photo_countObject

Returns the number of photos tracked by the PhotoSet



46
47
48
# File 'lib/aperture/photo_set.rb', line 46

def photo_count
  return size
end

#version_countObject

Returns the number of versions across all the photos tracked by the PhotoSet



51
52
53
# File 'lib/aperture/photo_set.rb', line 51

def version_count
  return inject(0) {|sum, photo| sum += photo.versions.size}      
end