Class: Flickr::Object::Photo::Size

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/flickr/object/photo/size.rb

Overview

Encapsulates the logic of managing sizes, including comparison, to make it easier to add dynamic size-changing methods to Flickr::Object::Photo.

Constant Summary collapse

NAMES =
Photo::SIZES
ABBREVIATIONS =

Used by Flickr for hash key names.

%w[sq t q s n m z c l h k o]
OTHER_ABBREVIATIONS =

Used by Flickr for generating source URLs.

%w[s t q m n - z c b]
LABELS =

Used by Flickr in response from “flickr.photos.getSizes”.

[
  "Square", "Thumbnail", "Large Square",
  "Small", "Small 320",
  "Medium", "Medium 640", "Medium 800",
  "Large", "Large 1600", "Large 2048",
  "Original",
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Size

Returns a new instance of Size.



52
53
54
# File 'lib/flickr/object/photo/size.rb', line 52

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



50
51
52
# File 'lib/flickr/object/photo/size.rb', line 50

def name
  @name
end

Class Method Details

.allObject



38
39
40
# File 'lib/flickr/object/photo/size.rb', line 38

def self.all
  NAMES.map { |name| new(name) }
end

.exists?(name) ⇒ Boolean

Returns:



46
47
48
# File 'lib/flickr/object/photo/size.rb', line 46

def self.exists?(name)
  all.include? new(name)
end

.typesObject



42
43
44
# File 'lib/flickr/object/photo/size.rb', line 42

def self.types
  all.map(&:type).uniq
end

Instance Method Details

#<=>(other) ⇒ Object

NAMES orders the sizes from smallest to largest, so we’re using that here.



80
81
82
# File 'lib/flickr/object/photo/size.rb', line 80

def <=>(other)
  NAMES.index(self.name) <=> NAMES.index(other.name)
end

#abbreviationObject



64
65
66
# File 'lib/flickr/object/photo/size.rb', line 64

def abbreviation
  ABBREVIATIONS[NAMES.index(name)]
end

#labelObject



72
73
74
# File 'lib/flickr/object/photo/size.rb', line 72

def label
  LABELS[NAMES.index(name)]
end

#numberObject



60
61
62
# File 'lib/flickr/object/photo/size.rb', line 60

def number
  name.split[1]
end

#other_abbreviationObject



68
69
70
# File 'lib/flickr/object/photo/size.rb', line 68

def other_abbreviation
  OTHER_ABBREVIATIONS[NAMES.index(name)]
end

#typeObject



56
57
58
# File 'lib/flickr/object/photo/size.rb', line 56

def type
  name.split[0]
end