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.



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

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

#file_sizeObject

Returns the value of attribute file_size.



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

def file_size
  @file_size
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



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

def analyze!
  self.file_size = File.size(path)
  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



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

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

#linesObject



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

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