Class: Pexels::CollectionMediaSet

Inherits:
PaginatedResponse show all
Defined in:
lib/pexels/collection_media_set.rb

Instance Attribute Summary collapse

Attributes inherited from PaginatedResponse

#page, #per_page, #total_results

Instance Method Summary collapse

Methods inherited from PaginatedResponse

#each, #next_page, #prev_page, #total_pages

Constructor Details

#initialize(response) ⇒ CollectionMediaSet

Returns a new instance of CollectionMediaSet.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pexels/collection_media_set.rb', line 8

def initialize(response)
  super
  @id = attrs.fetch('id')
  @data = attrs.fetch('media', []).map do |attrs|
    if attrs['type'] == 'Photo'
      Pexels::Photo.new(attrs)
    elsif attrs['type'] == 'Video'
      Pexels::Video.new(attrs)
    end
  end

rescue KeyError => exception
  raise Pexels::MalformedAPIResponseError.new(exception)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.


6
7
8
# File 'lib/pexels/collection_media_set.rb', line 6

def id
  @id
end

Instance Method Details

#photosObject


23
24
25
# File 'lib/pexels/collection_media_set.rb', line 23

def photos
  @photos ||= media.select { |m| m.is_a?(Pexels::Photo) }
end

#videosObject


27
28
29
# File 'lib/pexels/collection_media_set.rb', line 27

def videos
  @videos ||= media.select { |m| m.is_a?(Pexels::Video) }
end