Class: SrtSubtitleValidator::SrtBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/srt_subtitle_validator/srt_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#new(text) ⇒ SrtBlock #new(text) ⇒ SrtBlock

Returns a new instance of SrtBlock.

Overloads:

  • #new(text) ⇒ SrtBlock

    Block of subtitle content, it will be split automatically

    Parameters:

    • args (String)

      describe key param

  • #new(text) ⇒ SrtBlock

    Parameters:

    • dialog_number (String)

      number of sequence

    • dialog_time (String)

      time of sequence

    • dialog_text (String)

      subtitle text itself



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/srt_subtitle_validator/srt_block.rb', line 12

def initialize(*args)
  case args.count
  when 1
    blok = args[0].split("\n")
    @dialog_number = blok.shift.to_i
    @dialog_time = blok.shift
    @dialog_text = blok.join("\n")
  when 3
    @dialog_number = args.shift.to_i
    @dialog_time = args.shift
    @dialog_text = args.shift.strip
  else
    raise ArgumentError
  end
end

Instance Attribute Details

#dialog_numberObject

Returns the value of attribute dialog_number.



3
4
5
# File 'lib/srt_subtitle_validator/srt_block.rb', line 3

def dialog_number
  @dialog_number
end

#dialog_textObject

Returns the value of attribute dialog_text.



3
4
5
# File 'lib/srt_subtitle_validator/srt_block.rb', line 3

def dialog_text
  @dialog_text
end

#dialog_timeObject

Returns the value of attribute dialog_time.



3
4
5
# File 'lib/srt_subtitle_validator/srt_block.rb', line 3

def dialog_time
  @dialog_time
end

Instance Method Details

#to_sString

Returns subtitle sequence block.

Returns:

  • (String)

    subtitle sequence block



29
30
31
# File 'lib/srt_subtitle_validator/srt_block.rb', line 29

def to_s
  [@dialog_number, @dialog_time, @dialog_text].join("\n") + "\n\n"
end