Class: CSSFile

Inherits:
Object
  • Object
show all
Includes:
CssParser
Defined in:
lib/vtt2ass/css_file.rb

Overview

This class defines a CSS file for subtitles.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ CSSFile

Returns a new instance of CSSFile.



13
14
15
16
17
18
19
20
21
22
# File 'lib/vtt2ass/css_file.rb', line 13

def initialize(file_path)
  @file_path = file_path
  parser = CssParser::Parser.new
  parser.load_file!(file_path)
  @rules = []
  parser.each_selector do |selector, declarations, _specificity|
    css_obj = CSSRule.new(selector, declarations)
    @rules.push(css_obj) unless css_obj.name.empty?
  end
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



9
10
11
# File 'lib/vtt2ass/css_file.rb', line 9

def rules
  @rules
end

Instance Method Details

#find_rule(value) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/vtt2ass/css_file.rb', line 24

def find_rule(value)
  return_rule = nil
  @rules.each do |rule|
    if rule.name == value
      return_rule = rule
      break
    end
  end
  return_rule
end

#to_sObject



35
36
37
# File 'lib/vtt2ass/css_file.rb', line 35

def to_s
  @file_path
end