Class: Compass::Stats::SassFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ SassFile

Returns a new instance of SassFile.



62
63
64
# File 'lib/compass/stats.rb', line 62

def initialize(path)
  self.path = path
end

Instance Attribute Details

#file_sizeObject

Returns the value of attribute file_size.



60
61
62
# File 'lib/compass/stats.rb', line 60

def file_size
  @file_size
end

#pathObject

Returns the value of attribute path.



58
59
60
# File 'lib/compass/stats.rb', line 58

def path
  @path
end

#visitorObject (readonly)

Returns the value of attribute visitor.



59
60
61
# File 'lib/compass/stats.rb', line 59

def visitor
  @visitor
end

Instance Method Details

#analyze!Object



78
79
80
81
# File 'lib/compass/stats.rb', line 78

def analyze!
  self.file_size = File.size(path)
  visit_tree!
end

#contentsObject



65
66
67
# File 'lib/compass/stats.rb', line 65

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

#linesObject



82
83
84
# File 'lib/compass/stats.rb', line 82

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

#mixin_countObject



94
95
96
# File 'lib/compass/stats.rb', line 94

def mixin_count
  visitor.mixin_count
end

#mixin_def_countObject



91
92
93
# File 'lib/compass/stats.rb', line 91

def mixin_def_count
  visitor.mixin_def_count
end

#prop_countObject



88
89
90
# File 'lib/compass/stats.rb', line 88

def prop_count
  visitor.prop_count
end

#rule_countObject



85
86
87
# File 'lib/compass/stats.rb', line 85

def rule_count
  visitor.rule_count
end

#treeObject



68
69
70
71
72
# File 'lib/compass/stats.rb', line 68

def tree
  opts = Compass.configuration.to_sass_engine_options
  opts[:syntax] = path[-4..-1].to_sym
  @tree = Sass::Engine.new(contents, opts).to_tree
end

#visit_tree!Object



73
74
75
76
77
# File 'lib/compass/stats.rb', line 73

def visit_tree!
  @visitor = StatsVisitor.new
  tree.visit_depth_first(@visitor)
  @visitor
end