Class: Compass::Stats::CssFile

Inherits:
Object
  • Object
show all
Defined in:
lib/compass/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ CssFile

Returns a new instance of CssFile.



32
33
34
35
36
37
38
39
# File 'lib/compass/stats.rb', line 32

def initialize(path)
  require 'css_parser'
  self.path = path
  self.css = CssParser::Parser.new
  self.css.add_block!(contents)
  self.selector_count = 0
  self.prop_count = 0
end

Instance Attribute Details

#cssObject

Returns the value of attribute css.



30
31
32
# File 'lib/compass/stats.rb', line 30

def css
  @css
end

#pathObject

Returns the value of attribute path.



30
31
32
# File 'lib/compass/stats.rb', line 30

def path
  @path
end

#prop_countObject

Returns the value of attribute prop_count.



31
32
33
# File 'lib/compass/stats.rb', line 31

def prop_count
  @prop_count
end

#selector_countObject

Returns the value of attribute selector_count.



31
32
33
# File 'lib/compass/stats.rb', line 31

def selector_count
  @selector_count
end

Instance Method Details

#analyze!Object



46
47
48
49
50
51
52
53
# File 'lib/compass/stats.rb', line 46

def analyze!
  css.each_selector do |selector, declarations, specificity|
    sels = selector.split(/,/).size
    props = declarations.split(/;/).size
    self.selector_count += sels
    self.prop_count += props
  end
end

#contentsObject



40
41
42
# File 'lib/compass/stats.rb', line 40

def contents
  @contents ||= File.read(path)
end

#linesObject



43
44
45
# File 'lib/compass/stats.rb', line 43

def lines
  contents.inject(0){|m,c| m + 1 }
end