Class: YoutubeVideo::Timetag

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

Overview

comment’s time tag infomation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time:, comment:, end_time: nil, like_count: nil, tag_type: nil) ⇒ Timetag

Returns a new instance of Timetag.



8
9
10
11
12
13
14
# File 'lib/YPBT/time_tag.rb', line 8

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

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



7
8
9
# File 'lib/YPBT/time_tag.rb', line 7

def comment
  @comment
end

#durationObject (readonly)

Returns the value of attribute duration.



7
8
9
# File 'lib/YPBT/time_tag.rb', line 7

def duration
  @duration
end

#end_timeObject

Returns the value of attribute end_time.



7
8
9
# File 'lib/YPBT/time_tag.rb', line 7

def end_time
  @end_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



7
8
9
# File 'lib/YPBT/time_tag.rb', line 7

def start_time
  @start_time
end

#tag_typeObject

Returns the value of attribute tag_type.



7
8
9
# File 'lib/YPBT/time_tag.rb', line 7

def tag_type
  @tag_type
end

Class Method Details

.find(comment:) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/YPBT/time_tag.rb', line 37

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