Class: Pexels::Video

Inherits:
Object
  • Object
show all
Defined in:
lib/pexels/video.rb

Defined Under Namespace

Classes: File, Picture

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Video

Returns a new instance of Video.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pexels/video.rb', line 13

def initialize(attrs)
  @id = attrs.fetch('id')
  @height = attrs.fetch('height')
  @width = attrs.fetch('width')
  @url = attrs.fetch('url')
  @image = attrs.fetch('image')
  @duration = attrs.fetch('duration')
  @user = Pexels::User.new(
    id: attrs.fetch('user').fetch('id'),
    name: attrs.fetch('user').fetch('name'),
    url: attrs.fetch('user').fetch('url')
  )

  @files = attrs.fetch('video_files', []).map { |vf| Pexels::Video::File.new(vf) }

  @pictures = attrs.fetch('video_pictures', []).map { |vp| Pexels::Video::Picture.new(vp) }


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

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.


2
3
4
# File 'lib/pexels/video.rb', line 2

def duration
  @duration
end

#filesObject (readonly)

Returns the value of attribute files.


2
3
4
# File 'lib/pexels/video.rb', line 2

def files
  @files
end

#heightObject (readonly)

Returns the value of attribute height.


2
3
4
# File 'lib/pexels/video.rb', line 2

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.


2
3
4
# File 'lib/pexels/video.rb', line 2

def id
  @id
end

#imageObject (readonly)

Returns the value of attribute image.


2
3
4
# File 'lib/pexels/video.rb', line 2

def image
  @image
end

#picturesObject (readonly)

Returns the value of attribute pictures.


2
3
4
# File 'lib/pexels/video.rb', line 2

def pictures
  @pictures
end

#urlObject (readonly)

Returns the value of attribute url.


2
3
4
# File 'lib/pexels/video.rb', line 2

def url
  @url
end

#userObject (readonly)

Returns the value of attribute user.


2
3
4
# File 'lib/pexels/video.rb', line 2

def user
  @user
end

#widthObject (readonly)

Returns the value of attribute width.


2
3
4
# File 'lib/pexels/video.rb', line 2

def width
  @width
end

Instance Method Details

#photo?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/pexels/video.rb', line 39

def photo?
  false
end

#typeObject


35
36
37
# File 'lib/pexels/video.rb', line 35

def type
  'Video'
end

#video?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/pexels/video.rb', line 43

def video?
  true
end