Class: CSSRule

Inherits:
Object
  • Object
show all
Defined in:
lib/vtt2ass/css_rule.rb

Overview

This class defines a CSS rule that is included in the CSS file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selector, declarations) ⇒ CSSRule

Returns a new instance of CSSRule.



8
9
10
11
12
13
14
15
16
17
# File 'lib/vtt2ass/css_rule.rb', line 8

def initialize(selector, declarations)
  @name = reduce_selector(selector)
  @properties = []
  declarations.split(/;\s?/).each do |dec|
    temp = dec.split(/:\s?/)
    @properties.push(
      { key: temp.first, value: temp.last }
    )
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/vtt2ass/css_rule.rb', line 6

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



6
7
8
# File 'lib/vtt2ass/css_rule.rb', line 6

def properties
  @properties
end

Instance Method Details

#reduce_selector(selector) ⇒ Object

This method removes the generic selector from a block.



25
26
27
28
29
# File 'lib/vtt2ass/css_rule.rb', line 25

def reduce_selector(selector)
  selector.to_s.gsub(
    /\.rmp-container>\.rmp-content>\.rmp-cc-area>\.rmp-cc-container>\.rmp-cc-display>\.rmp-cc-cue\s?\.?/, ''
  )
end

#to_sObject



19
20
21
# File 'lib/vtt2ass/css_rule.rb', line 19

def to_s
  "#{@name} #{@properties}"
end