count 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/counter +3 -0
- data/lib/count.rb +97 -0
- metadata +49 -0
data/bin/counter
ADDED
data/lib/count.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'find'
|
4
|
+
require 'colored'
|
5
|
+
|
6
|
+
|
7
|
+
class Count
|
8
|
+
|
9
|
+
attr_accessor :count
|
10
|
+
|
11
|
+
LANG = {
|
12
|
+
:cpp =>"C++ Source",
|
13
|
+
:c =>"C Source",
|
14
|
+
:cs =>"C# ",
|
15
|
+
:h =>"C/C++ Header",
|
16
|
+
:hs =>"Haskell",
|
17
|
+
:java =>"Java",
|
18
|
+
:js =>"JavaScript",
|
19
|
+
:m =>"Objective C",
|
20
|
+
:php =>"PHP",
|
21
|
+
:py =>"Python",
|
22
|
+
:rb =>"Ruby",
|
23
|
+
:scala =>"Scala",
|
24
|
+
:sh =>"Shell",
|
25
|
+
:sml =>"Stand ML"
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
def self.count_file(file)
|
30
|
+
count = 0
|
31
|
+
comment = 0
|
32
|
+
open(file) do |file|
|
33
|
+
while line = file.gets
|
34
|
+
count = count + 1
|
35
|
+
|
36
|
+
begin
|
37
|
+
line.strip!
|
38
|
+
rescue => e
|
39
|
+
p e
|
40
|
+
end
|
41
|
+
|
42
|
+
if line.index("//") == 0 || line.index("#") == 0 || line.index('/*') == 0 || line.index('*')
|
43
|
+
comment += 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
[count, count - comment]
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.putsline
|
51
|
+
puts ("=" * 50).yellow
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.count(dir)
|
55
|
+
|
56
|
+
number = Hash.new
|
57
|
+
|
58
|
+
Find.find(File.expand_path(dir)).each do |file|
|
59
|
+
if File.file?(file)
|
60
|
+
ext = File.extname(file)[1..-1]
|
61
|
+
if ext
|
62
|
+
lang = ext.to_sym
|
63
|
+
if LANG.key?(lang)
|
64
|
+
num = count_file(file)
|
65
|
+
if !number.key? lang
|
66
|
+
number[lang] = [0,0]
|
67
|
+
end
|
68
|
+
number[lang][0] += num[0]
|
69
|
+
number[lang][1] += num[1]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
total = 0
|
77
|
+
total_pure = 0
|
78
|
+
|
79
|
+
putsline
|
80
|
+
puts " Lang count count(no comments)".blue
|
81
|
+
putsline
|
82
|
+
number.each do |lang, numberber|
|
83
|
+
str = "%12s %10d %10d" % [LANG[lang] , numberber[0], numberber[1]]
|
84
|
+
puts str.green
|
85
|
+
total += number[lang][0]
|
86
|
+
total_pure += number[lang][1]
|
87
|
+
end
|
88
|
+
putsline
|
89
|
+
puts ("%12s %10d %10d" % ["Total", total, total_pure]).blue
|
90
|
+
putsline
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: count
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lin Xiangyu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Code Line Counter. Now support C/C++/Obj-C/Ruby/Python/C#/Haskell/Scala/SML/PHP/JavaScript
|
15
|
+
email: lxyweb@gmail.com
|
16
|
+
executables:
|
17
|
+
- counter
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/count.rb
|
22
|
+
- !binary |-
|
23
|
+
YmluL2NvdW50ZXI=
|
24
|
+
homepage: http://linxiangyu.info
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.23
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: A Code Line Counter
|
48
|
+
test_files: []
|
49
|
+
has_rdoc:
|