class YoutubeVideo::Timetag

comment's time tag infomation

Attributes

comment[R]
duration[R]
end_time[R]
like_count[R]
start_time[R]
tag_type[R]

Public Class Methods

find(comment:) click to toggle source
# File lib/YPBT/time_tag.rb, line 38
def self.find(comment:)
  time_tag_pattern = /http.+?youtube.+?\?.+?t=.+?\>([0-9:]+)<\/a>/
  start_times_string = comment.text_display.scan time_tag_pattern
  tags = start_times_string.map do |match_parts|
    Timetag.new(start_time: match_parts[0], comment: comment)
  end
  tags
end
new(start_time:, comment:, end_time: nil, like_count: nil, tag_type: nil) click to toggle source
# File lib/YPBT/time_tag.rb, line 9
def initialize(start_time:, comment:, end_time: nil, like_count: nil,
               tag_type: nil)
  @start_time = string_to_time start_time
  @end_time = end_time
  @like_count = like_count ? like_count : comment.like_count
  @tag_type = tag_type
end

Public Instance Methods

end_time=(end_time) click to toggle source
# File lib/YPBT/time_tag.rb, line 21
def end_time=(end_time)
  @end_time = string_to_time end_time if end_time
end
tag_type=(tag_type) click to toggle source
# File lib/YPBT/time_tag.rb, line 34
def tag_type=(tag_type)
  @tag_type = TAG_TYPES[tag_type.to_sym] if tag_type
end

Private Instance Methods

string_to_time(time_string) click to toggle source
# File lib/YPBT/time_tag.rb, line 49
def string_to_time(time_string)
  time_unit = [:seconds, :minutes, :hours, :day, :weeks]
  time_array = time_string.scan(/[0-9]+/).map(&:to_i).reverse
  Duration.new(Hash[time_unit.zip(time_array)])
end