Class: YoutubeVideo::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/YPBT/runner.rb

Overview

Executable code for file(s) in bin/ folder

Class Method Summary collapse

Class Method Details

.comment_info(comment, index) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/YPBT/runner.rb', line 29

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

.output_info(video) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/YPBT/runner.rb', line 18

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

.run!(args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/YPBT/runner.rb', line 6

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