Class: Video

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

Constant Summary collapse

VALID_EXTENSIONS =
['.mp4', '.avi', '.mkv']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Video

Returns a new instance of Video.



20
21
22
23
# File 'lib/syndicate/lib/video.rb', line 20

def initialize(args = {})
  @title = args[:title]
  @path  = args[:path]
end

Instance Attribute Details

#description ⇒ Object (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/syndicate/lib/video.rb', line 4

def description
  @description
end

#path ⇒ Object (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/syndicate/lib/video.rb', line 4

def path
  @path
end

#thumbnail ⇒ Object (readonly)

Returns the value of attribute thumbnail.



4
5
6
# File 'lib/syndicate/lib/video.rb', line 4

def thumbnail
  @thumbnail
end

#title ⇒ Object (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/syndicate/lib/video.rb', line 4

def title
  @title
end

Class Method Details

.from_path(path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/syndicate/lib/video.rb', line 8

def self.from_path(path)
  if valid_extension? path    
    title = path.split('/').last
    title = strip_extension(title)
  
    Video.new(
      title: title,
      path:  path
    )
  end  
end

.strip_extension(path) ⇒ Object



27
28
29
30
31
# File 'lib/syndicate/lib/video.rb', line 27

def self.strip_extension(path)
  segments = path.split('.')
  segments.delete_at(-1)
  segments.join('.')
end

.valid_extension?(path) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/syndicate/lib/video.rb', line 33

def self.valid_extension?(path)
  VALID_EXTENSIONS.include? File.extname(path).downcase
end