Class: Count
- Inherits:
-
Object
- Object
- Count
- Defined in:
- lib/count.rb
Constant Summary collapse
- LANG =
{ :cpp =>"C++ Source", :c =>"C Source", :cs =>"C# ", :h =>"C/C++ Header", :hs =>"Haskell", :java =>"Java", :js =>"JavaScript", :m =>"Objective C", :php =>"PHP", :py =>"Python", :rb =>"Ruby", :scala =>"Scala", :sh =>"Shell", :sml =>"Stand ML", :coffee =>"CoffeeScript", :scss => "Scss", :erb => "Erb Templete", :haml => "Haml Templete", :slim => "Slim Templete", :less => "Less", :txt => "txt", :swift => "swift", :xml => "xml" }
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
Class Method Summary collapse
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
9 10 11 |
# File 'lib/count.rb', line 9 def count @count end |
Class Method Details
.count(dir) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/count.rb', line 63 def self.count(dir) number = Hash.new Find.find(File.(dir)).each do |file| if File.file?(file) ext = File.extname(file)[1..-1] if ext lang = ext.to_sym if LANG.key?(lang) num = count_file(file) if !number.key? lang number[lang] = [0,0] end number[lang][0] += num[0] number[lang][1] += num[1] end end end end total = 0 total_pure = 0 putsline puts " Lang count count(no comments)".blue putsline number.each do |lang, numberber| str = "%12s %10d %10d" % [LANG[lang] , numberber[0], numberber[1]] puts str.green total += number[lang][0] total_pure += number[lang][1] end putsline puts ("%12s %10d %10d" % ["Total", total, total_pure]).blue putsline end |
.count_file(file) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/count.rb', line 38 def self.count_file(file) count = 0 comment = 0 open(file) do |file| while line = file.gets count = count + 1 begin line.strip! rescue => e p e end if line.index("//") == 0 || line.index("#") == 0 || line.index('/*') == 0 || line.index('*') comment += 1 end end end [count, count - comment] end |
.putsline ⇒ Object
59 60 61 |
# File 'lib/count.rb', line 59 def self.putsline puts ("=" * 50).yellow end |