Sha256: 05ba1f20586678bc5e4dedc039749222647a1c535f850829f73767d0a05da5d1

Contents?: true

Size: 1009 Bytes

Versions: 4

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true

module YoutubeVideo
  # Executable code for file(s) in bin/ folder
  class Runner
    def self.run!(args)
      video_id = args[0] || ENV['YT_VIDEO_ID']
      unless video_id
        puts 'USAGE: YPBT [video_id]'
        exit(1)
      end

      video = YoutubeVideo::Video.find(video_id: video_id)

      output_info(video)
    end

    def self.output_info(video)
      title = video.title
      separator = Array.new(video.title.length) { '-' }.join
      video_info =
        video.comments.map.with_index do |comment, index|
          comment_info(comment, index)
        end.join

      [title, separator, video_info].join("\n")
    end

    def self.comment_info(comment, index)
      "#{index + 1}:\n"\
      "  Author: #{comment.author.author_name}\n"\
      "  Comment: #{comment.text_display}\n"\
      "  LIKE: #{comment.author.like_count}\n"\
      "  AuthorChannelUrl: #{comment.author.author_channel_url}\n"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
YPBT-0.2.9 lib/YPBT/runner.rb
YPBT-0.2.8 lib/YPBT/runner.rb
YPBT-0.2.6 lib/YPBT/runner.rb
YPBT-0.2.5 lib/YPBT/runner.rb