Class: Cejo::Media::Get

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

Overview

Get media pointed in url.

Constant Summary collapse

AUDIO_DIR =
Pathname.new(Dir.home).join('Music')
VIDEO_DIR =
Pathname.new(Dir.home).join('Videos')
AUDIO_FORMATS =
%w[vorbis flac mp3].freeze
VIDEO_FORMATS =
%w[mkv mp4 ogg].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Get

Returns a new instance of Get.



16
17
18
# File 'lib/cejo/media/get/get.rb', line 16

def initialize(info)
  @info = info
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



14
15
16
# File 'lib/cejo/media/get/get.rb', line 14

def info
  @info
end

Instance Method Details

#current_dirObject



20
21
22
# File 'lib/cejo/media/get/get.rb', line 20

def current_dir
  AUDIO_FORMATS.include?(info.codec) ? AUDIO_DIR : VIDEO_DIR
end

#execObject



39
40
41
42
43
# File 'lib/cejo/media/get/get.rb', line 39

def exec
  show_info

  Dir.chdir(current_dir) { system final_command }
end

#final_commandObject



24
25
26
# File 'lib/cejo/media/get/get.rb', line 24

def final_command
  AUDIO_FORMATS.include?(info.codec) ? info.audio_command : info.video_command
end

#show_infoObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/cejo/media/get/get.rb', line 28

def show_info
  puts <<~INFO
    Title: #{info.title}
    Url: #{info.url}
    Codec: #{info.codec}
    Folder: #{current_dir}
  INFO

  puts
end