Class: FlickrMocks::Models::PhotoSizes

Inherits:
Object
  • Object
show all
Defined in:
lib/flickr_mocks/models/photo_sizes.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ PhotoSizes

Returns a new instance of PhotoSizes.



4
5
6
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 4

def initialize(object)
  self.delegated_to_object= object
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

delegates methods that are returned by delegated instance method.



71
72
73
74
75
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 71

def method_missing(id,*args,&block)
  return @delegated_to_object.send(id,*args,&block) if  delegated_instance_methods.include?(id)
  return nil if possible_sizes.include?(name)
  super
end

Instance Method Details

#==(other) ⇒ Object

compares the complete internal state of two PhotoDetails objects rather than simply comparing object_id’s



51
52
53
54
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 51

def ==(other)
  return false unless self.class == other.class
  @delegated_to_object == other.instance_eval('@delegated_to_object')
end

#available_sizesObject

returns an array of symbols for the available sizes for the given photo



24
25
26
27
28
29
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 24

def available_sizes
  @available_sizes ||= sizes.map do |size|
    size.size.to_sym
  end
  @available_sizes
end

#collectionObject

returns a collection of sizes that can be used directly for WillPaginate.



32
33
34
35
36
37
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 32

def collection
  @collection ||= ::WillPaginate::Collection.create(1, sizes.length, sizes.length) do |obj|
    obj.replace(sizes)
  end
  @collection
end

#delegated_instance_methodsObject

returns true for delegated and regular methods



84
85
86
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 84

def delegated_instance_methods
  possible_sizes + FlickrMocks::Models::Helpers.array_accessor_methods
end

#idObject

returns the flickr id for the stored photo



9
10
11
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 9

def id
  @delegated_to_object.first.id
end

#initialize_copy(orig) ⇒ Object

compares value for internal state rather than object_id



89
90
91
92
93
94
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 89

def initialize_copy(orig)
  super
  @delegated_to_object = @delegated_to_object.map do |data|
    data.clone
  end
end

#methodsObject

returns delegated methods as well as regular methods



66
67
68
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 66

def methods
  delegated_instance_methods + old_methods
end

#old_methodsObject

metaprogramming methods



64
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 64

alias :old_methods :methods

#old_respond_to?Object



77
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 77

alias :old_respond_to? :respond_to?

#possible_sizesObject

returns an array that contains the symbol names for the possible sizes that a photo can have. Please note that not all sizes are available for every photo.



59
60
61
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 59

def possible_sizes
  Models::Helpers.possible_sizes
end

#respond_to?(method) ⇒ Boolean

returns true for delegated and regular methods

Returns:

  • (Boolean)


79
80
81
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 79

def respond_to?(method)
  old_respond_to?(method) || delegated_instance_methods.include?(method)
end

#secretObject

returns the flickr secret for the stored photo



14
15
16
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 14

def secret
  @delegated_to_object.first.secret
end

#sizesObject

returns array of PhotoSize objects available for the given photo



19
20
21
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 19

def sizes
  @delegated_to_object
end

#to_sObject

returns a string that encodes the name, width and height for all dimensions available for the photo. Sample return string is:

"square:75x75,thumbnail:67x100,small:161x240,medium:335x500"


43
44
45
46
47
# File 'lib/flickr_mocks/models/photo_sizes.rb', line 43

def to_s
  PhotoDimensions.new(@delegated_to_object.map do |size|
      "#{size.size}:#{size.width}x#{size.height}"
    end.join(',')).to_s
end