Class: ASSFile
- Inherits:
-
Object
- Object
- ASSFile
- Defined in:
- lib/vtt2ass/ASSFile.rb
Overview
This class defines an ASS subtitle file.
Instance Attribute Summary collapse
-
#ass_lines ⇒ Object
Returns the value of attribute ass_lines.
-
#ass_styles ⇒ Object
Returns the value of attribute ass_styles.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#convertVTTtoASS(vtt_file, font_family, font_size) ⇒ Object
This method receives a VTTFile object and font arguments creates new ASSLine with the params of each VTTLine.
-
#initialize(title, width, height) ⇒ ASSFile
constructor
Creates a new ASSFile instance and assigns the default values of instance variables.
-
#to_s ⇒ Object
This method concatenates the object data in the right order for a string output.
-
#writeToFile(file_path) ⇒ Object
This method writes the content of the ASSFile object into a file path that is provided.
Constructor Details
#initialize(title, width, height) ⇒ ASSFile
Creates a new ASSFile instance and assigns the default values of instance variables.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vtt2ass/ASSFile.rb', line 13 def initialize(title, width, height) @width = width @height = height @header = [ '[Script Info]', "Title: #{title}", 'ScriptType: v4.00+', 'Collisions: Normal', 'PlayDepth: 0', "PlayResX: #{@width}", "PlayResY: #{@height}", 'WrapStyle: 0', 'ScaledBorderAndShadow: yes', '', '[V4+ Styles]', 'Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding' ] @events = [ '', '[Events]', 'Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text' ] @ass_styles = [] @ass_lines = [] end |
Instance Attribute Details
#ass_lines ⇒ Object
Returns the value of attribute ass_lines.
9 10 11 |
# File 'lib/vtt2ass/ASSFile.rb', line 9 def ass_lines @ass_lines end |
#ass_styles ⇒ Object
Returns the value of attribute ass_styles.
9 10 11 |
# File 'lib/vtt2ass/ASSFile.rb', line 9 def ass_styles @ass_styles end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/vtt2ass/ASSFile.rb', line 8 def height @height end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/vtt2ass/ASSFile.rb', line 8 def title @title end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
8 9 10 |
# File 'lib/vtt2ass/ASSFile.rb', line 8 def width @width end |
Instance Method Details
#convertVTTtoASS(vtt_file, font_family, font_size) ⇒ Object
This method receives a VTTFile object and font arguments creates new ASSLine with the params of each VTTLine. All those ASSLine are stored in an array. It also creates an array of ASSStyle that will be used in the ASS style list.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vtt2ass/ASSFile.rb', line 43 def convertVTTtoASS(vtt_file, font_family, font_size) vtt_file.lines.each do |line| @ass_lines.push(ASSLine.new(line.style, line.time_start, line.time_end, line.text)) style_exists = false @ass_styles.each do |style| if (style.style_name == line.style) then style_exists = true break end end if not style_exists then @ass_styles.push(ASSStyle.new(line.style, line.params, font_family, font_size, @width, @height)) end end end |
#to_s ⇒ Object
This method concatenates the object data in the right order for a string output.
70 71 72 |
# File 'lib/vtt2ass/ASSFile.rb', line 70 def to_s return @header + @ass_styles + @events + @ass_lines end |
#writeToFile(file_path) ⇒ Object
This method writes the content of the ASSFile object into a file path that is provided.
61 62 63 64 65 66 |
# File 'lib/vtt2ass/ASSFile.rb', line 61 def writeToFile(file_path) File.open(file_path, 'w') do |line| line.print "\ufeff" line.puts self.to_s end end |