Class: Ass::Span
- Inherits:
-
Object
- Object
- Ass::Span
- Defined in:
- lib/mpv_ass/span.rb
Overview
Represents a styled ASS text fragment.
Instance Attribute Summary collapse
-
#content ⇒ String
(also: #to_s)
Gets or changes the plain text fragment content.
Instance Method Summary collapse
-
#bare ⇒ self
Removes all style tags.
-
#blur(strength) ⇒ self
Sets the blur strength.
-
#bold(value = true) ⇒ self
Sets bold text rendering.
-
#color(value) ⇒ self
Sets the font color.
-
#font(name) ⇒ self
Sets the font name.
-
#initialize(content = nil) ⇒ Span
constructor
Creates an ASS::Span text fragment.
-
#italic(value = true) ⇒ self
Sets italic text rendering.
-
#outline(size, color) ⇒ self
Sets the outline thickness and color.
-
#shadow(size) ⇒ self
Sets the shadow size.
-
#size(value) ⇒ self
Sets the font size.
-
#strike(value = true) ⇒ self
Sets strikethrough text rendering.
-
#to_script ⇒ String
Converts the text fragment to ASS syntax.
-
#underline(value = true) ⇒ self
Sets underline text rendering.
Constructor Details
#initialize(content = nil) ⇒ Span
Creates an ASS::Span text fragment.
15 16 17 18 |
# File 'lib/mpv_ass/span.rb', line 15 def initialize(content=nil) @content = content @tags = {} end |
Instance Attribute Details
#content ⇒ String Also known as: to_s
Gets or changes the plain text fragment content.
10 11 12 |
# File 'lib/mpv_ass/span.rb', line 10 def content @content end |
Instance Method Details
#bare ⇒ self
Removes all style tags.
104 105 106 107 |
# File 'lib/mpv_ass/span.rb', line 104 def @tags.clear self end |
#blur(strength) ⇒ self
Sets the blur strength.
97 98 99 100 |
# File 'lib/mpv_ass/span.rb', line 97 def blur(strength) @tags["blur"] = strength.to_f self end |
#bold(value = true) ⇒ self
Sets bold text rendering.
31 32 33 34 |
# File 'lib/mpv_ass/span.rb', line 31 def bold(value=true) @tags["b"] = value ? 1 : 0 self end |
#color(value) ⇒ self
Sets the font color.
71 72 73 74 |
# File 'lib/mpv_ass/span.rb', line 71 def color(value) @tags["1c"] = value.is_a?(Color) ? value : Color.new(value) self end |
#font(name) ⇒ self
Sets the font name.
23 24 25 26 |
# File 'lib/mpv_ass/span.rb', line 23 def font(name) @tags["fn"] = name.to_s self end |
#italic(value = true) ⇒ self
Sets italic text rendering.
39 40 41 42 |
# File 'lib/mpv_ass/span.rb', line 39 def italic(value=true) @tags["i"] = value ? 1 : 0 self end |
#outline(size, color) ⇒ self
Sets the outline thickness and color.
80 81 82 83 84 |
# File 'lib/mpv_ass/span.rb', line 80 def outline(size, color) @tags["3c"] = color.is_a?(Color) ? color : Color.new(color) @tags["bord"] = size.to_i self end |
#shadow(size) ⇒ self
Sets the shadow size.
89 90 91 92 |
# File 'lib/mpv_ass/span.rb', line 89 def shadow(size) @tags["shad"] = size.to_i self end |
#size(value) ⇒ self
Sets the font size.
63 64 65 66 |
# File 'lib/mpv_ass/span.rb', line 63 def size(value) @tags["fs"] = value.to_i self end |
#strike(value = true) ⇒ self
Sets strikethrough text rendering.
55 56 57 58 |
# File 'lib/mpv_ass/span.rb', line 55 def strike(value=true) @tags["s"] = value ? 1 : 0 self end |
#to_script ⇒ String
Converts the text fragment to ASS syntax.
111 112 113 114 115 116 117 118 119 |
# File 'lib/mpv_ass/span.rb', line 111 def to_script = @tags.map do |(key, value)| value = value.to_script if value.is_a?(Color) "\\#{key}#{value}" end head, tail = "{#{.join}}", "{\\r}" unless .empty? content = @content.to_s.gsub("\\", "\\\\").gsub("{", "\\{").gsub("}", "\\}").gsub("\n", "\\N") "#{head}#{content}#{tail}" end |
#underline(value = true) ⇒ self
Sets underline text rendering.
47 48 49 50 |
# File 'lib/mpv_ass/span.rb', line 47 def underline(value=true) @tags["u"] = value ? 1 : 0 self end |