Class: Snapcat::Media::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/snapcat/media.rb

Constant Summary collapse

IMAGE =
0
VIDEO =
1
VIDEO_NOAUDIO =
2
FRIEND_REQUEST =
3
FRIEND_REQUEST_IMAGE =
4
FRIEND_REQUEST_VIDEO =
5
FRIEND_REQUEST_VIDEO_NOAUDIO =
6

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Type

Returns a new instance of Type.



43
44
45
# File 'lib/snapcat/media.rb', line 43

def initialize(options = {})
  @code = code_from(options[:code], options[:data])
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



41
42
43
# File 'lib/snapcat/media.rb', line 41

def code
  @code
end

Instance Method Details

#file_extensionObject



47
48
49
50
51
52
53
# File 'lib/snapcat/media.rb', line 47

def file_extension
  if image?
    'jpg'
  elsif video?
    'mp4'
  end
end

#image?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/snapcat/media.rb', line 55

def image?
  [IMAGE, FRIEND_REQUEST_IMAGE].include? @code
end

#video?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
# File 'lib/snapcat/media.rb', line 59

def video?
  [
    VIDEO, VIDEO_NOAUDIO, FRIEND_REQUEST_VIDEO, FRIEND_REQUEST_VIDEO_NOAUDIO
  ].include? @code
end