Class: CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/deadlist/cli.rb

Overview

The CLI is the ‘session’ created by the main class, managing arguments passed in and housing methods for scraping and downloading shows.

Instance Method Summary collapse

Constructor Details

#initialize(version, args) ⇒ CLI

Returns a new instance of CLI.



9
10
11
12
13
14
15
16
# File 'lib/deadlist/cli.rb', line 9

def initialize(version, args)
    @version = version
    @args = {}
    @show = nil

    startup_text
    parse_arguments(args)
end

Instance Method Details

#download_showObject

Validates format isn’t for test, and passes directory + format arguments to the download method of a Show



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/deadlist/cli.rb', line 35

def download_show
    download_format = @args[:format]

    if download_format == "test"
      puts "Test Download, skipping"
    elsif @show.has_format?(download_format)
        download_path = setup_directories(@show)
        @show.download_tracks(download_path, download_format)
    else
        puts "\n❌ #{download_format} not found for this show! #{@show.tracks[0].available_formats} available"
    end
end

#parse_arguments(args) ⇒ Object

Reads arguments passed at the command line and maps them to an instance object



19
20
21
22
23
24
# File 'lib/deadlist/cli.rb', line 19

def parse_arguments(args)
    args.each do |arg|
        key, value = arg.split('=')
        @args[key.tr('--', '').to_sym] = value
    end
end

Creates new show object with link given populated with metadata and track details



27
28
29
30
31
32
# File 'lib/deadlist/cli.rb', line 27

def scrape_links
    @show = Show.new(@args[:show])
    puts "\n💿 #{@show.tracks.length} tracks found!"
rescue => e
    puts "\n❌ Scraping failed: #{e.message}"
end