Class: CLI
- Inherits:
-
Object
- Object
- CLI
- 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 Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#show ⇒ Object
readonly
Returns the value of attribute show.
Instance Method Summary collapse
-
#create_show ⇒ Object
Creates new show object with link given populated with metadata and track details.
-
#download_show ⇒ Object
Downloads show tracks or displays dry-run preview.
-
#initialize(version, args, logger: Logger.new($stdout)) ⇒ CLI
constructor
A new instance of CLI.
Constructor Details
#initialize(version, args, logger: Logger.new($stdout)) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/deadlist/cli.rb', line 13 def initialize(version, args, logger: Logger.new($stdout)) @version = version @args = {} @show = nil @logger = logger @logger.formatter = proc do |severity, datetime, progname, msg| "#{msg}\n" end startup_text parse_arguments(args) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
11 12 13 |
# File 'lib/deadlist/cli.rb', line 11 def args @args end |
#show ⇒ Object (readonly)
Returns the value of attribute show.
11 12 13 |
# File 'lib/deadlist/cli.rb', line 11 def show @show end |
Instance Method Details
#create_show ⇒ Object
Creates new show object with link given populated with metadata and track details
27 28 29 30 31 32 33 34 35 |
# File 'lib/deadlist/cli.rb', line 27 def create_show show_id = @args[:ids].first extracted_id = extract_show_id(show_id) @show = Show.new(extracted_id, @args[:format], logger: @logger) @logger.info "💿 #{@show.name} - #{@show.tracks.length} tracks found!" rescue => e @logger.error "❌ Scraping failed: #{e.message}" end |
#download_show ⇒ Object
Downloads show tracks or displays dry-run preview
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/deadlist/cli.rb', line 38 def download_show if @args[:dry_run] @logger.info "🔍 Dry Run: #{@show.name} will be downloaded with #{@show.tracks.count} tracks" @show.tracks.each do |track| @logger.info " #{track.pos} - #{track.title}" end else download_directory = setup_directories(@show, @args[:directory]) @show.download_tracks(download_directory) end rescue => e @logger.error "❌ Download failed: #{e.message}" end |