Class: CSSRule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selector, declarations) ⇒ CSSRule

Returns a new instance of CSSRule.



4
5
6
7
8
9
10
11
12
13
# File 'lib/vtt2ass/css_rule.rb', line 4

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.



2
3
4
# File 'lib/vtt2ass/css_rule.rb', line 2

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



2
3
4
# File 'lib/vtt2ass/css_rule.rb', line 2

def properties
  @properties
end

Instance Method Details

#reduce_selector(selector) ⇒ Object



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

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

#to_sObject



15
16
17
# File 'lib/vtt2ass/css_rule.rb', line 15

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