Class: Compass::Stats::CssFile
- Inherits:
-
Object
- Object
- Compass::Stats::CssFile
- Defined in:
- lib/compass/stats.rb
Instance Attribute Summary collapse
-
#css ⇒ Object
Returns the value of attribute css.
-
#file_size ⇒ Object
Returns the value of attribute file_size.
-
#path ⇒ Object
Returns the value of attribute path.
-
#prop_count ⇒ Object
Returns the value of attribute prop_count.
-
#selector_count ⇒ Object
Returns the value of attribute selector_count.
Instance Method Summary collapse
- #analyze! ⇒ Object
- #contents ⇒ Object
-
#initialize(path) ⇒ CssFile
constructor
A new instance of CssFile.
- #lines ⇒ Object
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
#css ⇒ Object
Returns the value of attribute css.
30 31 32 |
# File 'lib/compass/stats.rb', line 30 def css @css end |
#file_size ⇒ Object
Returns the value of attribute file_size.
32 33 34 |
# File 'lib/compass/stats.rb', line 32 def file_size @file_size end |
#path ⇒ Object
Returns the value of attribute path.
30 31 32 |
# File 'lib/compass/stats.rb', line 30 def path @path end |
#prop_count ⇒ Object
Returns the value of attribute prop_count.
31 32 33 |
# File 'lib/compass/stats.rb', line 31 def prop_count @prop_count end |
#selector_count ⇒ Object
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 |
#contents ⇒ Object
41 42 43 |
# File 'lib/compass/stats.rb', line 41 def contents @contents ||= File.read(path) end |
#lines ⇒ Object
44 45 46 |
# File 'lib/compass/stats.rb', line 44 def lines contents.inject(0){|m,c| m + 1 } end |