Class: SrtSubtitleValidator::SrtFile
- Inherits:
-
Object
- Object
- SrtSubtitleValidator::SrtFile
- Defined in:
- lib/srt_subtitle_validator/srt_file.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Instance Method Summary collapse
-
#initialize(source, logger = nil) ⇒ SrtFile
constructor
A new instance of SrtFile.
- #inspect ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(source, logger = nil) ⇒ SrtFile
Returns a new instance of SrtFile.
11 12 13 14 15 16 |
# File 'lib/srt_subtitle_validator/srt_file.rb', line 11 def initialize(source, logger = nil) @logger = logger || Logger.new(STDOUT) @errors = [] @srt_dialog_blocks = {} @source = source.dup.encode(Encoding::UTF_8).gsub(/\r/, '') end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
6 7 8 |
# File 'lib/srt_subtitle_validator/srt_file.rb', line 6 def blocks @blocks end |
#errors ⇒ Object
Returns the value of attribute errors.
7 8 9 |
# File 'lib/srt_subtitle_validator/srt_file.rb', line 7 def errors @errors end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/srt_subtitle_validator/srt_file.rb', line 6 def length @length end |
Instance Method Details
#inspect ⇒ Object
30 31 32 |
# File 'lib/srt_subtitle_validator/srt_file.rb', line 30 def inspect "<SrtSubtitleValidator::SrtFile ...>" end |
#valid? ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/srt_subtitle_validator/srt_file.rb', line 18 def valid? @blocks = @source.split(/^\r?\n+/m).map do |n| i = SrtBlock.new(n) @srt_dialog_blocks[i.dialog_number] = i i end @length = !@blocks.empty? && @blocks.last.dialog_number || 0 @errors << 'File is zero size' if @length.zero? @errors << 'Numbers sequence is corrupted' unless @blocks.count == @length @errors.empty? end |