Class: Flickr::Object::Photo::Size
- Inherits:
-
Object
- Object
- Flickr::Object::Photo::Size
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
NAMES orders the sizes from smallest to largest, so we’re using that here.
- #abbreviation ⇒ Object
-
#initialize(name) ⇒ Size
constructor
A new instance of Size.
- #label ⇒ Object
- #number ⇒ Object
- #other_abbreviation ⇒ Object
- #type ⇒ Object
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
#name ⇒ Object (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
.all ⇒ Object
38 39 40 |
# File 'lib/flickr/object/photo/size.rb', line 38 def self.all NAMES.map { |name| new(name) } end |
.exists?(name) ⇒ Boolean
46 47 48 |
# File 'lib/flickr/object/photo/size.rb', line 46 def self.exists?(name) all.include? new(name) end |
.types ⇒ Object
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 |
#abbreviation ⇒ Object
64 65 66 |
# File 'lib/flickr/object/photo/size.rb', line 64 def abbreviation ABBREVIATIONS[NAMES.index(name)] end |
#label ⇒ Object
72 73 74 |
# File 'lib/flickr/object/photo/size.rb', line 72 def label LABELS[NAMES.index(name)] end |
#number ⇒ Object
60 61 62 |
# File 'lib/flickr/object/photo/size.rb', line 60 def number name.split[1] end |
#other_abbreviation ⇒ Object
68 69 70 |
# File 'lib/flickr/object/photo/size.rb', line 68 def other_abbreviation OTHER_ABBREVIATIONS[NAMES.index(name)] end |
#type ⇒ Object
56 57 58 |
# File 'lib/flickr/object/photo/size.rb', line 56 def type name.split[0] end |