Class: Pexels::Photo
- Inherits:
-
Object
- Object
- Pexels::Photo
- Defined in:
- lib/pexels/photo.rb
Instance Attribute Summary collapse
-
#avg_color ⇒ Object
readonly
Returns the value of attribute avg_color.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Photo
constructor
A new instance of Photo.
- #photo? ⇒ Boolean
- #type ⇒ Object
- #video? ⇒ Boolean
Constructor Details
#initialize(attrs) ⇒ Photo
Returns a new instance of Photo.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pexels/photo.rb', line 10 def initialize(attrs) @id = attrs.fetch('id') @height = attrs.fetch('height') @width = attrs.fetch('width') @url = attrs.fetch('url') @user = Pexels::User.new( id: attrs.fetch('photographer_id'), name: attrs.fetch('photographer'), url: attrs.fetch('photographer_url') ) @src = attrs.fetch('src') @avg_color = attrs.fetch('avg_color') rescue KeyError => exception raise Pexels::MalformedAPIResponseError.new(exception) end |
Instance Attribute Details
#avg_color ⇒ Object (readonly)
Returns the value of attribute avg_color.
2 3 4 |
# File 'lib/pexels/photo.rb', line 2 def avg_color @avg_color end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
2 3 4 |
# File 'lib/pexels/photo.rb', line 2 def height @height end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/pexels/photo.rb', line 2 def id @id end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
2 3 4 |
# File 'lib/pexels/photo.rb', line 2 def src @src end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
2 3 4 |
# File 'lib/pexels/photo.rb', line 2 def url @url end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
2 3 4 |
# File 'lib/pexels/photo.rb', line 2 def user @user end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
2 3 4 |
# File 'lib/pexels/photo.rb', line 2 def width @width end |
Instance Method Details
#photo? ⇒ Boolean
31 32 33 |
# File 'lib/pexels/photo.rb', line 31 def photo? true end |
#type ⇒ Object
27 28 29 |
# File 'lib/pexels/photo.rb', line 27 def type 'Photo' end |
#video? ⇒ Boolean
35 36 37 |
# File 'lib/pexels/photo.rb', line 35 def video? false end |