Class: FlickrMocks::Models::PhotoSize

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

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ PhotoSize

Returns a new instance of PhotoSize.



4
5
6
# File 'lib/flickr_mocks/models/photo_size.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 array methods to the @dimensions object



38
39
40
41
# File 'lib/flickr_mocks/models/photo_size.rb', line 38

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

Instance Method Details

#==(other) ⇒ Object

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



25
26
27
# File 'lib/flickr_mocks/models/photo_size.rb', line 25

def ==(other)
  @delegated_to_object == other.instance_eval('@delegated_to_object')
end

#delegated_instance_methodsObject

returns list of methods that are delegated to other objects



32
33
34
# File 'lib/flickr_mocks/models/photo_size.rb', line 32

def delegated_instance_methods
  @delegated_to_object.methods(false).push(:flickr_type)
end

#idObject

returns the flickr id for the given photo



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

def id
  source.split('/')[-1].split('_')[0]
end

#initialize_copy(orig) ⇒ Object

compares value for internal state rather than object_id



57
58
59
60
# File 'lib/flickr_mocks/models/photo_size.rb', line 57

def initialize_copy(orig)
  super
  @delegated_to_object = @delegated_to_object.clone
end

#methodsObject

returns delegated methods as well as regular methods



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

def methods
  delegated_instance_methods + old_methods
end

#old_methodsObject



50
# File 'lib/flickr_mocks/models/photo_size.rb', line 50

alias :old_methods :methods

#old_respond_to?Object



43
# File 'lib/flickr_mocks/models/photo_size.rb', line 43

alias :old_respond_to? :respond_to?

#respond_to?(method, type = false) ⇒ Boolean

returns true for delegated and regular methods

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/flickr_mocks/models/photo_size.rb', line 45

def respond_to?(method,type=false)
  return true if delegated_instance_methods.include?(method)
  old_respond_to?(method,type)
end

#secretObject

returns the flickr secret for the given photo



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

def secret
  source.split('/')[-1].split('_')[1]
end

#sizeObject

returns the string that contains the photo’s size



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

def size
  label.to_s.downcase.sub(/\s+/,'_')
end